slice-machine icon indicating copy to clipboard operation
slice-machine copied to clipboard

`ERR_REQUIRE_ESM` error on `start-slicemachine` due to incorrect `node-fetch` version

Open angeloashmore opened this issue 3 years ago • 2 comments

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.

angeloashmore avatar May 17 '22 00:05 angeloashmore

Running into the same issue, would be great if this got resolved

scott-the-brewer avatar May 23 '22 11:05 scott-the-brewer

Same issue here

joelcorey avatar Jun 27 '22 19:06 joelcorey

Confirming I am using node-fetch v3 which breaks while node-fetch 2.x works As my project needs ESM version, I am stucked :)

cptflammin avatar Sep 20 '22 11:09 cptflammin

Solved with latest helpers https://community.prismic.io/t/type-error-when-building-package-that-uses-prismicio-helpers/10938/10

cptflammin avatar Sep 20 '22 12:09 cptflammin

Tested. No longer an issue with the latest version of Slice Machine (^0.4.2)

angeloashmore avatar Sep 22 '22 11:09 angeloashmore