You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using importing ESM package in a CJS project using dynamic import, it will throw the error of unable to require ESM file. This only happens when dynamic importing package that uses default export, while named export works fine. When inspecting the built file, it seems that the await import has been transformed to await require() for both named and default exports, but somehow breaks when the package uses default export.
dynamic import of package that uses default export should work just like named export.
😯 Current Behavior
dynamic import of package that uses default export throws error
Error [ERR_REQUIRE_ESM]: require() of ES Module D:\test\test-parcel\node_modules\ora\index.js from D:\test\test-parcel\index.js not supported.
Instead change the require of D:\test\test-parcel\node_modules\ora\index.js in D:\test\test-parcel\index.js to a dynamic import() which is available in all CommonJS modules.
at newRequire (D:\test\test-parcel\index.js:58:18)
at newRequire (D:\test\test-parcel\index.js:45:18)
at localRequire (D:\test\test-parcel\index.js:84:35)
at D:\test\test-parcel\index.js:152:36
at 3ZIAi.cf029259061c951f (D:\test\test-parcel\index.js:157:3)
at newRequire (D:\test\test-parcel\index.js:71:24) {
code: 'ERR_REQUIRE_ESM'
}
💁 Possible Solution
i dont know.
🔦 Context
Trying to import package from ESM to CJS, but fails
mathjs package is an ESM package that uses named export. If you comment out ora import line and console log, you should see that the compile file can run successful with a function logged in console.
ora package is also an ESM package but uses default export. If you comment out mathjs import line and console log, you will see the error being thrown.
🌍 Your Environment
Software
Version(s)
Parcel
2.12.0
Node
20.18.0
npm/Yarn
10.9.0
Operating System
Windows 10.0.22631 Build 22631
The text was updated successfully, but these errors were encountered:
🐛 bug report
When using importing ESM package in a CJS project using dynamic import, it will throw the error of unable to require ESM file. This only happens when dynamic importing package that uses default export, while named export works fine. When inspecting the built file, it seems that the
await import
has been transformed toawait require()
for both named and default exports, but somehow breaks when the package uses default export.🎛 Configuration (.babelrc, package.json, cli command)
package.json
🤔 Expected Behavior
dynamic import of package that uses default export should work just like named export.
😯 Current Behavior
dynamic import of package that uses default export throws error
💁 Possible Solution
i dont know.
🔦 Context
Trying to import package from ESM to CJS, but fails
💻 Code Sample
index.cjs
mathjs
package is an ESM package that uses named export. If you comment outora
import line and console log, you should see that the compile file can run successful with a function logged in console.ora
package is also an ESM package but uses default export. If you comment outmathjs
import line and console log, you will see the error being thrown.🌍 Your Environment
The text was updated successfully, but these errors were encountered: