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 verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
Binaries:
Node: 16.13.0
npm: 8.5.2
Yarn: 1.22.15
pnpm: 6.32.2
Relevant packages:
next: 12.1.1-canary.5
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I have a package in my node_modules which uses an ESM package (is-stream@^3.0.0). The package using the ESM package is trying to require it which I know is an error and I have raised an issue in the downstream package here. This is fine as next offers a great option experimental.esmExternals: 'loose' in order to fix this issue.
The bug that I have noticed is that so long as I have installed the package (in my example it's @monsonjeremy/esm-external-package) I don't even need to enable experimental.esmExternals: 'loose', I am able to run the application just fine without getting this error. If however I link to the package locally, then I get the error:
ESM packages (is-stream) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals
I am really confused why linking has different behavior then installing the package from NPM and if this is expected.
Expected Behavior
I should have uniform behavior when linking the package locally or installing it from NPM.
It feels like my local linked package has been detected as a local dependency instead of an external => Next seems to rebuild it instead of treating it as a module. During the build, it transforms my ES modules and turns import into require.
I feel like you might have the same issue with yarn link as with Yalc
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I have a package in my
node_modules
which uses an ESM package (is-stream@^3.0.0
). The package using the ESM package is trying torequire
it which I know is an error and I have raised an issue in the downstream package here. This is fine as next offers a great optionexperimental.esmExternals: 'loose'
in order to fix this issue.The bug that I have noticed is that so long as I have installed the package (in my example it's
@monsonjeremy/esm-external-package
) I don't even need to enableexperimental.esmExternals: 'loose'
, I am able to run the application just fine without getting this error. If however I link to the package locally, then I get the error:I am really confused why linking has different behavior then installing the package from NPM and if this is expected.
Expected Behavior
I should have uniform behavior when linking the package locally or installing it from NPM.
To Reproduce
I have created an example repo here, which can be used to see the issue: https://github.com/monsonjeremy/esm-external-example-repo
Steps:
cd example-package
npm install && npm run build && npm link
cd ../example-app
npm install
6: Run
npm run dev
localhost:3000
npm link @monsonjeremy/esm-external-package
npm run dev
The text was updated successfully, but these errors were encountered: