Re: Using Require in V2?

For some our modules we have to use require or else the module always fails. But, if we try to use require (and only require) in a step in V2, we get the following error: ‘import’ and ‘export’ may appear only with ‘sourceType: module’ (2:0)

Sample code is below. 
const shippo = require('shippo')(process.env.YOURSHIPPOID);
export default defineComponent({
  async run({ steps, $ }) {
      // this Node.js code will execute when the step runs
return shippo
  }
});
1 Like

I’m facing the same error. Anyone know how to get past it?

Hi @osseonews and @mweitzman

I can help with this! Pipedream v2 workflows are ESM modules, not CommonJS modules.

You’ll just need to switch from require to import.

So for example:

// CommonJS
const shippo = require('shippo')

// ESM
import shippo from 'shippo'

Please refer to our dedicated section in the docs for handling these types of errors:

1 Like