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
I faced with a similar issue. We use internal UI library lives in the same monorepository when our Next.js application exist and connected via workspace:* feature. When we switched to "type": "module" in the library's package.json, which is our requirement to ship the UI library outside of the current monorepository, our Next.js application build has broken (but building itself has been done successfully).
Do we have some workaround for this issue? It completely brakes our websites.
Link to the code that reproduces this issue
https://github.com/jantimon/reproduction-webpack-import-module-bug/tree/nextjs
To Reproduce
git clone https://github.com/jantimon/reproduction-webpack-import-module-bug.git
git checkout nextjs
npm i
npm run dev
I am using the Webpack loader API
this.importModule
which invokesvm.runInThisContext
to execute the module code.However, as soon as the
package.json
file includes"type": "module"
vm.runInThisContext
does not have access torequire
andmodule
anymore:./banner.ts
loader.cjs
next.config.mjs
next generates the following code:
module.exports = require("cowsay");
which does not work in CSM and therefore breaks:Current vs. Expected behavior
it would be nice if adding
"type" = "module"
when using the Webpack loader APIthis.importModule
would not crash nextjsProvide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 Binaries: Node: 20.9.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: 8.9.2 Relevant Packages: next: 14.1.0 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.3
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
According to @alexander-akait it is not a webpack issue: webpack/webpack#18023
The text was updated successfully, but these errors were encountered: