Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
angeloashmore opened this issue May 17, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@angeloashmore
Copy link
Member

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

> prismic-toolbar-issue-66-repro@0.1.0 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 angeloashmore added the bug Something isn't working label May 17, 2022
@scott-the-brewer
Copy link

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

@joelcorey
Copy link

Same issue here

@cptflammin
Copy link

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
Copy link

@angeloashmore angeloashmore self-assigned this Sep 22, 2022
@angeloashmore
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants