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
Failed to compile.
./packages/test/index.mjs
export 'foo' (reexported as 'foo') was not found in './test.mjs' (module has no exports)
Import trace for requested module:
./packages/test/index.mjs
./app/page.js
> Build failed because of webpack errors
Verify canary release
I verified that the issue exists in the latest Next.js canary release
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
As shown in the codesandbox, the problem is due to a file in node_modules that has a function that assigns to a local variable called module, with a property called exports.
This seems to cause Next.js to think the file has no exports anymore. If you rename module to anything else it works fine. My guess is faulty CommonJS detection. That should only apply to the global module, not when a local variable that happens to be named module is defined. If this is found in node_modules, it is hard to workaround. This pattern is often found in CommonJS libraries that were published with an ESM wrapper.
The text was updated successfully, but these errors were encountered:
devongovett
changed the title
Local variable named module in a node_module breaks build
Local variable named module in an ESM node_module breaks build
Oct 28, 2023
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/nextjs-module-repro-257rt8?file=%2Fpackages%2Ftest%2Ftest.mjs%3A5%2C1
To Reproduce
Run
next build
in the above sandbox.Current vs. Expected behavior
Build fails. It should succeed.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 Binaries: Node: 18.18.0 npm: 9.8.1 Yarn: 1.22.19 pnpm: 8.7.6 Relevant Packages: next: 14.0.0 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: N/A Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
As shown in the codesandbox, the problem is due to a file in node_modules that has a function that assigns to a local variable called
module
, with a property calledexports
.This seems to cause Next.js to think the file has no exports anymore. If you rename
module
to anything else it works fine. My guess is faulty CommonJS detection. That should only apply to the globalmodule
, not when a local variable that happens to be namedmodule
is defined. If this is found in node_modules, it is hard to workaround. This pattern is often found in CommonJS libraries that were published with an ESM wrapper.The text was updated successfully, but these errors were encountered: