Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM interoperability issue (default.default export) #11949

Open
JulianKingman opened this issue Oct 2, 2024 · 0 comments
Open

ESM interoperability issue (default.default export) #11949

JulianKingman opened this issue Oct 2, 2024 · 0 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@JulianKingman
Copy link

JulianKingman commented Oct 2, 2024

Environment

 System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 84.56 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.20.4/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
    pnpm: 9.10.0 - ~/.nvm/versions/node/v18.20.4/bin/pnpm
    bun: 1.1.0 - ~/.bun/bin/bun
    Watchman: 2024.08.26.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 123.1.64.122
    Chrome: 125.0.6422.142
    Safari: 17.6
  npmPackages:
    next: latest => 14.2.14 
    next-auth: latest => 4.24.8 
    react: ^18.3.1 => 18.3.1 

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

@JulianKingman 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant