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

blitz-auth: Fix webpack from following next-auth #4160

Merged
merged 7 commits into from
Jul 3, 2023

Conversation

siddhsuresh
Copy link
Member

@siddhsuresh siddhsuresh commented Jun 19, 2023

Closes: ?

What are the changes and their implications?

in betav29, webpack follows next-auth with webpack resolve when the package name is passed directly.

  • Upgrade CI to use pnpm latest

Bug Checklist

  • Changeset added (run pnpm changeset in the root directory)

@changeset-bot
Copy link

changeset-bot bot commented Jun 19, 2023

🦋 Changeset detected

Latest commit: 86a9058

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@blitzjs/auth Patch
blitz Patch
next-blitz-auth Patch
@blitzjs/rpc Patch
@blitzjs/next Patch
@blitzjs/codemod Patch
@blitzjs/config Patch
@blitzjs/generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tordans
Copy link
Contributor

tordans commented Jun 29, 2023

Just a quick +1 for this PR. We tried migrating our blitz app to the app folder this week but got stuck on errors that sound like they will be solved by this PR. We are using blitz-auth, not next-auth for our app. We will try again once this is merged…

@siddhsuresh
Copy link
Member Author

Hey @tordans sorry for that, we are working to merge this soon.

@kodiakhq kodiakhq bot merged commit c5572be into main Jul 3, 2023
@kodiakhq kodiakhq bot deleted the siddhsuresh/fix-next-auth-resolveing branch July 3, 2023 17:36
@datner
Copy link
Contributor

datner commented Jul 3, 2023

OK! Now let's publish this 😃

@variousred
Copy link

need this. ♥

@variousred
Copy link

Bummer, i thought this would fix this

node ➜ /workspace (devcontainer-clean) $ yarn  dev 
yarn run v1.22.19
$ blitz dev
Loaded env from /workspace/.env.development
Loaded env from /workspace/.env.local
Loaded env from /workspace/.env
/workspace/node_modules/next/dist/client/index.js
✔ Next.js was successfully patched with a React Suspense fix
✔ Routes manifest was successfully generated
- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- error Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './core/init' is not defined by "exports" in /workspace/node_modules/next-auth/package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
    at resolveExports (node:internal/modules/cjs/loader:554:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1012:27)
    at /workspace/node_modules/next/dist/server/require-hook.js:189:36
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18) {
  type: 'Error',
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
error Command failed with exit code 1.

@datner
Copy link
Contributor

datner commented Jul 5, 2023

@variousred this looks entirely unrelated to the next-auth situation 🤔
Do you have "moduleResolution": "node16" or "nodenext" or "bundler" in your tsconfig?

@variousred
Copy link

variousred commented Jul 6, 2023

@datner

"moduleResolution": "nodenext",

@datner
Copy link
Contributor

datner commented Jul 6, 2023

@variousred
Yeah this is an issue with next-auth. They probably do not expect someone to use next-auth/core/init directly, so it is not part of the "exports" field as seen here

blitz can just patch them, but it's not that simple:

  1. if blitz patches next-auth it will be required to bundle it with @blitzjs/auth because patches don't magically apply
  2. it will not actually solve the issue, this will have to be done on next-auths side. Which they might not want as we don't know if they consider this api to be "internal"
  3. nextjs can't handle "moduleResolution": "nodenext", or any of the other I named above. So even if this problem is solved, I don't think you'll be able to actually use your nextjs application.

If you did manage to make nextjs work with "moduleResolution": "nodenext" and "type": "module" please let me know because this is considered unsolvable from the outside as far as next see it 😄

tl;dr
switch to "moduleResolution": "node"

@variousred
Copy link

i get the same thing with "moduleResolution": "node"

@variousred
Copy link

variousred commented Jul 7, 2023

whats the "right" way to use blitz-auth with a provider like SIWE, rainbowkit?

just following
https://blitzjs.com/docs/next-auth
and
https://docs.login.xyz/integrations/nextauth.js

@variousred
Copy link

variousred commented Jul 7, 2023

linking to #4171

@datner
Copy link
Contributor

datner commented Jul 8, 2023

@variousred do you perhaps still use "type": "module" in your package json?

@variousred
Copy link

No

@variousred
Copy link

whats the "right" way to use blitz-auth with a provider like SIWE, rainbowkit?

just following https://blitzjs.com/docs/next-auth and https://docs.login.xyz/integrations/nextauth.js

has anyone done this? is this not working generally?

@siddhsuresh
Copy link
Member Author

Hey @variousred , we are currently in the process of working with next auth to fix this issue by exposing the required functions upstream.
But even this will be made in a newer adapter for @auth/core rather than the current next-auth.
For your use right now and what works at the moment would be a manual patch for next-auth using pnpm patch next-auth and add these exports in the package.json of the next-auth package.

Thank you for patience, we are working to make this more stable.

@variousred
Copy link

thanks @siddhsuresh much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants