Open asbermudez opened 1 year ago
Hey @asbermudez - does the problem persist with the latest version? If so, can you please provide a reproduction (https://nuxt.com/docs/community/reporting-bugs#create-a-minimal-reproduction) so that we can locally replicate and resolve the problem?
If nothing follows we'll close this issue in a couple of days.
Thanks!
Hi @BracketJohn don't mean to hijack this issue in case this is unrelated, but I can see the exact same error message regarding circular dependencies, which seems to happen when you try to use #auth
within e.g. server/utils
Export "NuxtAuthHandler" of module "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/nuxtAuthHandler.mjs" was reexported through module "node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/index.mjs" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
Either change the import in "server/api/[...].ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Minimal repro here: https://stackblitz.com/edit/github-1ye2j4 - run npm run build
to see the error - using nuxt-auth v0.5.0
Thanks for the reproduction - will have a look into it 💯
Ok just been playing around with this some more - I can get the error to go away in the minimal repro by upgrading to nuxt-auth 0.6.0-beta.2, however it still persists in the project I'm working on even after upgrading.
I'll see if I can get a minimal repro going on 0.6.0-beta.2 too if that would help.
Ok so have found a patch - as the error message hints, the issue seems to be around the re-export that's happening via ./runtime/server/services/index
Updating src/modules.ts
to point to the original module instead of the re-export seems to solve the issue.
nitroConfig.alias['#auth'] = resolve('./runtime/server/services/authjs/nuxtAuthHandler')
...
addTemplate({
filename: 'types/auth.d.ts',
getContents: () => [
'declare module \'#auth\' {',
` const getServerSession: typeof import('${resolve('./runtime/server/services/authjs/nuxtAuthHandler')}').getServerSession`,
` const getToken: typeof import('${resolve('./runtime/server/services/authjs/nuxtAuthHandler')}').getToken`,
` const NuxtAuthHandler: typeof import('${resolve('./runtime/server/services/authjs/nuxtAuthHandler')}').NuxtAuthHandler`,
options.provider.type === 'local' ? genInterface('SessionData', (options.provider as any).sessionDataType) : '',
'}'
].join('\n')
})
@BracketJohn I can submit a PR If you're happy with this solution? Not sure what side effects this may or may not have or whether the re-export module is still needed if you went this route.
Possible fix here 🔧 https://github.com/moussaclarke/nuxt-auth/commit/fad97166b552b293ba61e7864ce2654d7da03e54
I couldn't see that anything else uses the re-export module so went ahead and deleted it.
Hi there! Any updates? I have same problem.
Nuxt project info: 10:23:14
------------------------------
- Operating System: Windows_NT
- Node Version: v20.7.0
- Nuxt Version: 3.11.2
- CLI Version: 3.11.1
- Nitro Version: 2.9.6
- Package Manager: pnpm@9.0.1
- Builder: -
- User Config: typescript, devtools, runtimeConfig, css, app, build, modules, cron, pinia, experimental, auth
- Runtime Modules: @unocss/nuxt@0.58.9, @bg-dev/nuxt-naiveui@1.13.0, @pinia/nuxt@0.5.1, @vueuse/nuxt@10.9.0, @sidebase/nuxt-auth@0.7.2, nuxt-cron@1.5.1, dayjs-nuxt@2.1.9, @nuxt/eslint@0.3.8
- Build Modules: -
------------------------------
@mttzzz Could you please provide a minimal reproduction repository? I am not sure if this wasn't fixed in the latest release (0.7.2) or in alpha (0.8.0-alpha.1), as #747 has done some work on type generation
Environment
Windows_NT
v18.14.0
3.2.2
2.2.2
npm@9.3.1
vite
app
,modules
,postcss
,vite
,typescript
,runtimeConfig
,imports
,umami
,auth
,nitro
@sidebase/nuxt-auth@0.4.2
,nuxt-umami@1.2.0
,@pinia/nuxt@0.4.6
,@vuestic/nuxt@1.0.9
-
Reproduction
Set the
/server/api/auth/[...].ts
with Auth0 as provider as explained in documentationRun
npx nuxi build
Describe the bug
The build output is giving the following error:
There's more errors in other files where I import the
getToken
through the#auth
path with the same error but just referring to the specific function.Additional context
No response
Logs