sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.29k stars 164 forks source link

'./core' is not defined by "exports" in next-auth/package.json #518

Closed karis closed 1 year ago

karis commented 1 year ago

Environment

Nuxi 3.6.5 8:38:19 AM

RootDir: /Users/me/Development/vercel/drclinic-app
Nuxt project info: (copied to clipboard)


  • Operating System: Darwin
  • Node Version: v16.20.1
  • Nuxt Version: 3.6.5
  • Nitro Version: 2.4.0
  • Package Manager: pnpm@8.6.12
  • Builder: vite
  • User Config: modules, auth, typescript, gitsUi, devtools, imports, css, i18n, colorMode, vite, experimental
  • Runtime Modules: @morpheme/nuxt@1.0.0-beta.11, @nuxtjs/tailwindcss@6.8.0, @nuxtjs/color-mode@3.3.0, @nuxtjs/i18n@8.0.0-beta.10, @sidebase/nuxt-auth@0.6.0-beta.4
  • Build Modules: -

Reproduction

it is my first using @sidebase/nuxt-auth i start from scratch

npx nuxi@latest init my-app pnpm i -D @sidebase/nuxt-auth

then configure nuxt.config.ts

export default defineNuxtConfig({ modules: [ '@sidebase/nuxt-auth', ], auth: { globalAppMiddleware: true, },

next i install Prisma 5.1.1

then pnpm run dev

Describe the bug

Error while running project

[worker reload] [worker init] Package subpath './core' is not defined by "exports" in /Users/Me/Development/vercel/drclinic-app/node_modules/next-auth/package.json imported from /Users/Me/Development/vercel/drclinic-app/.nuxt/dev/index.mjs

Additional context

No response

Logs

✔ Nitro built in 162 ms                                                                                                                        nitro 8:31:16 AM

[8:31:16 AM]  ERROR  [worker reload] [worker init] Package subpath './core' is not defined by "exports" in /Users/Me/Development/vercel/drclinic-app/node_modules/next-auth/package.json imported from /Users/Me/Development/vercel/drclinic-app/.nuxt/dev/index.mjs

  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 packageResolve (node:internal/modules/esm/resolve:833:14)
  at moduleResolve (node:internal/modules/esm/resolve:901:20)
  at defaultResolve (node:internal/modules/esm/resolve:1115:11)
  at nextResolve (node:internal/modules/esm/loader:163:28)
  at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)


🙏🏼please help me...  
ghost commented 1 year ago

Not related to Prisma package, but next-auth

Due to https://github.com/nextauthjs/next-auth/commit/05ff6ae221b0434784e056de4bff6e3e45c49552 fix in https://github.com/nextauthjs/next-auth/releases/tag/next-auth%404.23.0

A solution is to downgrade to next-auth@4.22.5 Or, add manualy into package.json for the next-auth package :

"./core": {
      "types": "./core/index.d.ts",
      "default": "./core/index.js"
    },
Guasertex commented 1 year ago

I had the same problem and it was solved after the following installation ( example below via yarn )

yarn add next-auth@4.21.1 --legacy-peer-deps

karis commented 1 year ago

nextauthjs/next-auth@05ff6ae

i already test it, and i got this log..

[10:26:39 PM] AUTH_NO_ORIGIN: No origin - this is an error in production, see https://sidebase.io/nuxt-auth/resources/errors. You can ignore this during development [nitro] [uncaughtException] ReferenceError: require is not defined in ES module scope, you can use import instead 10:26:39 PM at file:///Users/Me/Development/vercel/drclinic-app/.nuxt/dev/index.mjs:1332:26 at ModuleJob.run (node:internal/modules/esm/module_job:192:25) at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24) at async loadESM (node:internal/process/esm_loader:40:7) at async handleMainPromise (node:internal/modules/run_main:66:12)`

Guasertex commented 1 year ago

Copy it to the nuxt.config.ts file.

export default defineNuxtConfig({ modules: ['@sidebase/nuxt-auth',], auth: { enableGlobalAppMiddleware: true, origin: 'http://localhost:3000', } ) This will only work if you are running on a local host, in other cases I can't vouch that there won't be any errors will be other problems during deploy on static host, so learn to use the .env file in your project.

dschreij commented 1 year ago

Easiest is to add

"overrides": {
    "next-auth": "4.22.5"
  },

to your package.json and to a clean install with npm install (you may need to delete package-lock.json and node_modules)

Once this issue is fixed, you can simply remove the override.

wanxe commented 1 year ago

I was trying just the same but no luck:

still having the following error: WARN (node-resolve plugin) Could not resolve import "next-auth/core" (i'm using node v18.12.1 with npm namespaces)

Easiest is to add

"overrides": {
    "next-auth": "4.22.5"
  },

to your package.json and to a clean install with npm install (you may need to delete package-lock.json and node_modules)

Once this issue is fixed, you can simply remove the override.

karis commented 1 year ago

Copy it to the nuxt.config.ts file.

export default defineNuxtConfig({ modules: ['@sidebase/nuxt-auth',], auth: { enableGlobalAppMiddleware: true, origin: 'http://localhost:3000', } ) This will only work if you are running on a local host, in other cases I can't vouch that there won't be any errors will be other problems during deploy on static host, so learn to use the .env file in your project.

still no clue..

i'll check my enviroment again and try to rebuild from scratch..

wanxe commented 1 year ago

I finally managed to solve it, I did a reinstall from scratch removing package-lock.json and using the "next-auth" version: "^4.18.1".

Now i'm receiving a 404 from the Github side but this is another problem.

bjornol commented 1 year ago

The

"overrides": { "next-auth": "4.22.5" },

workes for me

andreasvirkus commented 1 year ago

As others have mentioned, I got rid of the build error by fixing next-auth to version 4.12.1 (which is the exact version of the peer dependency), it seems anything 4.23.x breaks it?

"dependencies": {
  "next-auth": "4.21.1"
}
christianlmc commented 1 year ago

Just upgraded to "nuxt": "^3.7.0" and I started getting the same error. I'm using "@sidebase/nuxt-auth": "^0.6.0-beta.4",. Doing what @dschreij suggested worked for me

DraftProducts commented 1 year ago

Same for me with 0.5.0 on 3.7.0 release of nuxt. Thanks @andreasvirkus, works well for me !

kikiimdev commented 1 year ago

As others have mentioned, I got rid of the build error by fixing next-auth to version 4.12.1 (which is the exact version of the peer dependency), it seems anything 4.23.x breaks it?

"dependencies": {
  "next-auth": "4.21.1"
}

Same for me with 0.5.0 on 3.7.0 release of nuxt. Thanks @andreasvirkus, works well for me !

Thanks, this one work for me on nuxt 3.7.0 downgrade @sidebase/nuxt-auth to 0.50 and next-auth to 4.21.1

quroom commented 1 year ago

Me either, nuxt 3.7.1 nuxt-auth 0.5.0 next-auth 4.21.1 works well.

karis commented 1 year ago

Not related to Prisma package, but next-auth

Due to nextauthjs/next-auth@05ff6ae fix in https://github.com/nextauthjs/next-auth/releases/tag/next-auth%404.23.0

A solution is to downgrade to next-auth@4.22.5 Or, add manualy into package.json for the next-auth package :

"./core": {
      "types": "./core/index.d.ts",
      "default": "./core/index.js"
    },

hi all,

i already did it, it solved for development. it was running well.

then.. i build run into docker container.

here is what i found


myApp_lite | Error [ERR_MODULE_NOT_FOUND]: 
Cannot find module '/app/.output/server/node_modules/next-auth/core/index.js' 
imported from /app/.output/server/index.mjs
zoey-kaiser commented 1 year ago

Duplicate of #514

tmlmt commented 1 year ago

Not related to Prisma package, but next-auth

Due to nextauthjs/next-auth@05ff6ae fix in https://github.com/nextauthjs/next-auth/releases/tag/next-auth%404.23.0

A solution is to downgrade to next-auth@4.22.5 Or, add manualy into package.json for the next-auth package :

"./core": {
      "types": "./core/index.d.ts",
      "default": "./core/index.js"
    },

Hey @agennari, thanks for this ! Patching next-auth with this did the trick. It seems we're in a deadend here as the maintainer rejected a PR in that direction (https://github.com/nextauthjs/next-auth/pull/8496) @zoey-kaiser will you pin the peerDependency to the latest compatible next-auth i.e. v4.22.5, or what's the plan?