ErrorMust use import to load ES Module when deploying Pipedream workflow

This topic was automatically generated from Slack. You can find the original thread here.

Rinat Uspensky : But I see
ErrorMust use import to load ES Module: /opt/ee/node_modules/array-differ/index.js require() of ES modules is not supported. require() of /opt/ee/node_modules/array-differ/index.js from /opt/ee/c_lKfEMma/index.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules. Instead rename /opt/ee/node_modules/array-differ/index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from /opt/ee/node_modules/array-differ/package.json.

Michelle Bergeron : It looks like the error is saying to use import instead of require. I would try changing this line:
**const** arrayDiffer = require('array-differ');
to this:
const arrayDiffer = import('array-differ');

Michelle Bergeron : Actually, this is how the documentation shows it:

import arrayDiffer from 'array-differ';

Giao Phan : Unfortunately, we can’t support import in code steps. you can try const { default: arrayDiffer} = await import ('array-differ')

Raymond Camden : Should this work with node-fetch? const fetch = await import(‘node-fetch’);
When I try to use fetch, I’m told it’s not a function

Giao Phan : try const { default: fetch} = await import('node-fetch')

Raymond Camden : that worked… can i ask why? i mean - i get most of the syntax, but it isnt clicking

Giao Phan : When you are using esm and you export a default object (instead of using named exports), the async import returns that as an object with a default key.

Raymond Camden : i mostly get that :wink: do yall document how to use ESM stuff? it (not w/ PD, but in Node in general) has been biting me in the rear a lot all of a sudden

Giao Phan : Yeah, we are trying to figure out our strategy. There has definitely been a noticeable shift to ESM only packages in the new year, but we can’t make the shift without AWS supporting it as well.

Giao Phan : + you can’t import CJS into ESM packages, so would make some packages completely broken. It’s a bit of a cluster honestly.

Giao Phan : Here’s the best article that I’ve encountered on it: Node Modules at War: Why CommonJS and ES Modules Can’t Get Along | by Dan Fabulich | Code Red

Raymond Camden : any plans for Pipedream docs to talk about it?even if there isn’t a great one size fits all solution, I can see this coming up more and more

Danny Roosevelt : yea, @UMT4G7E5P and I chatted about this and think that’s a good idea and would be helpful. I created an issue here to track it for us in case you’re interested in following along.