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 importing next-auth through several layers of ESM packages, when it reaches the nextJS app, default exports arrive wrapped in an object like this: { default: defaultExport }
After many dead ends and hours of searching, I found a concise explanation of what the issue is: evanw/esbuild#1719 (comment)
I'm not 100% sure what the solution is, but it seems that next-auth is getting compiled to CJS with __esModule set to true, which causes unpredictable behavior, depending on which compiler is handling it.
How to reproduce
I'm currently experiencing this in my monorepo. Run npx turbo install && npx turbo build in the root directory, you will see the build fails because CredentialsProvider is importing as { default: [Function function] }, rather than [Function function].
Expected behavior
Expected behavior would be that it imports the default without wrapping it. This appears to be a quirk of Webpack, and I'm working on how to work around it, but the fundamental solution appears to be in changing the way the package (next-auth) is compiled.
The text was updated successfully, but these errors were encountered:
JulianKingman
added
bug
Something isn't working
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
labels
Oct 2, 2024
Agreed! The irony is that this issue prevented me from moving my project to ESM only 😕
That said, there should be a way to make this a non-breaking change, by just adding an extra export. I'm not sure what settings would need to change, but as it says here, you would replace code like this:
This compatibility pattern has an odd effect where f.default.default.default... out to infinity is equal to f, but nonetheless, all runtimes and bundlers will bind a default import of the module to a callable f.
If you're open to it I can see what's needed and make a PR
Environment
Reproduction URL
https://github.com/CollaborativeEconomics/monorepo/tree/next-auth-esm-issue
Describe the issue
When importing next-auth through several layers of ESM packages, when it reaches the nextJS app, default exports arrive wrapped in an object like this: { default: defaultExport }
After many dead ends and hours of searching, I found a concise explanation of what the issue is: evanw/esbuild#1719 (comment)
I'm not 100% sure what the solution is, but it seems that next-auth is getting compiled to CJS with
__esModule
set to true, which causes unpredictable behavior, depending on which compiler is handling it.How to reproduce
I'm currently experiencing this in my monorepo. Run
npx turbo install && npx turbo build
in the root directory, you will see the build fails because CredentialsProvider is importing as{ default: [Function function] }
, rather than[Function function]
.Expected behavior
Expected behavior would be that it imports the default without wrapping it. This appears to be a quirk of Webpack, and I'm working on how to work around it, but the fundamental solution appears to be in changing the way the package (next-auth) is compiled.
Additional info:
https://arethetypeswrong.github.io/?p=next-auth%404.24.8
The text was updated successfully, but these errors were encountered: