-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Bug]: importing ESM node_module causing ERR_REQUIRE_ESM #1283
Comments
should also add esm support for |
Seems you can use However currently Remix uses |
nowadays there are a lot of esm modules in npm, so all of them don't work in remix. |
I am not going back to |
I am also having this issue |
According to the source code remix/packages/remix-dev/config.ts Line 170 in 1fd7096
|
+1 esm support is needed |
+1 esm supprt is needed |
See documentation on gotchas for how to import ESM-modules: https://remix.run/docs/en/v1/pages/gotchas#importing-esm-packages |
Tracked in #109 |
I tried this gotcha approach mentioned in the remix documentation while I was using nanoId() and it didn't work and today itself when I was trying to use swiper it didn't work. |
@Ricky428 I'm also trying the solution but the CLI tells me
meanwhile, the exact string of the package is in |
i just opened #6928 |
This might not work for everyone, but it worked for me.
|
@yarapolana Thanks! You nailed it!! Your solution worked for me and I don't get this error anymore. |
Adding 💿 remix dev
info building...
info built (2.8s)
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'D:\Code\Remix\example.com\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///D:/Code/Remix/example.com/build/<stdin>:1:1
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
at run (D:\Code\Remix\example.com\node_modules\.pnpm\@remix-run+serve@2.5.1_typescript@5.3.3\node_modules\@remix-run\serve\dist\cli.js:113:15) Previously, I got the filename here so I changed it from |
Which Remix packages are impacted?
remix
(Remix core)create-remix
@remix-run/architect
@remix-run/cloudflare-workers
@remix-run/dev
@remix-run/express
@remix-run/netlify
@remix-run/node
@remix-run/react
@remix-run/serve
@remix-run/server-runtime
@remix-run/vercel
What version of Remix are you using?
1.1.1
What version of Node are you using? Minimum supported version is 14.
v16.13.1
Steps to Reproduce
install @nodestrap/navbar using NPM:
npm i @nodestrap/navbar
then import & render the
import { Navbar } from '@nodestrap/navbar'
....
....
Expected Behavior
it should run perfectly. Tested in nextjs / react app with no problem
Actual Behavior
error [ERR_REQUIRE_ESM]: require() of ES Module ..... from ....index.js not supported.
Instead change the require .... to a dynamic import() which is available in all CommonJS modules.
I saw the problem is the generated build/index.js is a common js.
It tries to import an ESM module using
require('some-esm-module')
Is there any way to change the generated build/index.js as ESM module?
CommonJS cannot import ESM but ESM can import CommonJS.
The text was updated successfully, but these errors were encountered: