`ERR_REQUIRE_ESM` error on `start-slicemachine` due to incorrect `node-fetch` version
Versions
- slice-machine-ui: 0.3.7
- node: 16.15.0
Reproduction
Run the following commands to create a reproduction.
npx create-next-app
cd app-name
# Install node-fetch v3 (this could also come from another dependency)
npm i node-fetch
npx @slicemachine/init
Steps to reproduce
Start the project created above.
npm run slicemachine
What is expected?
Slice Machine starts.
What is actually happening?
[nix-shell:~]$ npm run slicemachine
> [email protected] slicemachine
> start-slicemachine
Launching server...
[slice-machine] /[path-to-project]/node_modules/slice-machine-ui/build/server/src/index.js:141
undefined
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /[path-to-project]/node_modules/node-fetch/src/index.js from /[path-to-project]/node_modules/slice-machine-ui/build/server/src/index.js not supported.
Instead change the require of /[path-to-project]/node_modules/node-fetch/src/index.js in /[path-to-project]/node_modules/slice-machine-ui/build/server/src/index.js to a dynamic import() which is available in all CommonJS modules.
at Object.newLoader [as .js] (/[path-to-project]/node_modules/pirates/lib/index.js:141:7)
at Object.<anonymous> (/[path-to-project]/node_modules/slice-machine-ui/build/server/src/index.js:16:38) {
code: 'ERR_REQUIRE_ESM'
}
This happens because slice-machine-ui does not list node-fetch@cjs as a dependency. It is listed in the monorepo's root package.json, which does not get copied to the published package.
Current workaround: install a CJS-compatible version of node-fetch into a project. This will conflict if the project actually needs the ESM version.
Running into the same issue, would be great if this got resolved
Same issue here
Confirming I am using node-fetch v3 which breaks while node-fetch 2.x works As my project needs ESM version, I am stucked :)
Solved with latest helpers https://community.prismic.io/t/type-error-when-building-package-that-uses-prismicio-helpers/10938/10
Tested. No longer an issue with the latest version of Slice Machine (^0.4.2)