-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 in gatsby-recipes #33713
Comments
Any update on this? Its affecting me too. |
Gatsby use
|
output: { | |
dir: `dist`, | |
entryFileNames: `[name].js`, | |
format: "cjs", | |
sourcemap: true, | |
}, |
All import
Declaration will be transform to require
Declaration
import remarkMdx from "remark-mdx" |
to
https://cdn.jsdelivr.net/npm/gatsby-recipes@1.2.0/dist/graphql-server/server.js
var remarkMdx = require('remark-mdx');
https://github.com/mdx-js/mdx/blob/main/packages/remark-mdx/package.json#L34
remark-mdx breaking change -> pr mdx-js/mdx#1661
The CommonJS module require
always treats the files it references as CommonJS.
Using require
to load an ES module is not supported because ES modules have asynchronous execution. Instead, use import() to load an ES module from a CommonJS module.
sindresorhus's The ESM move
I think more and more npm package will be esm-only
in the future (e.g. sindresorhus/meta#15 (comment)), so gatsby need care this trends.
Temporary workaround
lock remark-mdx
version in gatsby-recipes/package.json
- ^2.0.0-next.4
+ 2.0.0-next.9
But it's not long-term solutions, esm
is future. cc @wardpeet
https://nodejs.org/api/esm.html#import-expressions It’s worth noting that the only way to import ESM files from a CJS module is using dynamic |
Any updates? |
in newly created gatsby project moves @mdx-js/mdx versions from "v1" to ==> "^2.1.1". Then this is seen: The expectation is newer versions of packages will be always compatible, updated and use the latest standards and best practices. If I manually edit package.json and revert @mdx-jx/mdx and @mdx-js/react versions to I may be missing something very silly basic, but what?? |
Think this needs to be reopened |
I have probably the error. |
I just bumped into this trying to run an old project. I solved it by locking remark-mdx using the resolutions field in package.json:
Don't know if it will be picked up by all package managers. I was using Yarn classic, and had to remove my node_modules first. |
Preliminary Checks
Description
gatsby/packages/gatsby-recipes/package.json
Line 53 in d04f563
remark-mdx@^2.0.0-next.4
resolves toremark-mdx@2.0.0-rc.1
which is ESM only packageReproduction Link
https://codesandbox.io/s/cocky-sound-og3zh?file=/package.json
Steps to Reproduce
yarn add -D docz react react-dom
yarn docz dev
Expected Result
All works without any errors.
Actual Result
ERR_REQUIRE_ESM error
Environment
System: OS: macOS 11.6 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Shell: 5.8 - /bin/zsh Binaries: Node: 16.10.0 - /var/folders/h2/gn99zpsn25j5w47332yy8jfw0000gn/T/yarn--1635416469908-0.7042407843892959/node Yarn: 1.22.13 - /var/folders/h2/gn99zpsn25j5w47332yy8jfw0000gn/T/yarn--1635416469908-0.7042407843892959/yarn npm: 7.24.0 - ~/.nvm/versions/node/v16.10.0/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 95.0.4638.54 Firefox: 91.0.2 Safari: 15.0
Config Flags
No response
The text was updated successfully, but these errors were encountered: