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.24k stars 158 forks source link

Wrong chunk bundling output circular dependencies when importing from provided '#auth' #252

Open asbermudez opened 1 year ago

asbermudez commented 1 year ago

Environment

Reproduction

Set the /server/api/auth/[...].ts with Auth0 as provider as explained in documentation

import Auth0Provider from 'next-auth/providers/auth0';
import { NuxtAuthHandler } from '#auth';

const config = useRuntimeConfig();

export default NuxtAuthHandler({
  pages: {
    signIn: '/login',
    signOut: '/logout',
  },
  secret: config.auth0.appSecret,
  providers: [
    // @ts-expect-error You need to use .default here for it to work during SSR. 
   // May be fixed via Vite at some point
    Auth0Provider.default({
      clientId: config.public.auth0.clientId,
      clientSecret: config.auth0.clientSecret,
      issuer: config.public.auth0.domain,
      checks: 'pkce',
    }),
  ],
});

Run npx nuxi build

Describe the bug

The build output is giving the following error:

[WebServer] 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/auth/[...].ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

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

$ npx nuxi build
Nuxi 3.2.2                                                                  15:06:02
Nuxt 3.2.2 with Nitro 2.2.2                                                 15:06:02
i nuxt-auth setup starting                                        nuxt-auth 15:06:04
√ nuxt-auth setup done                                            nuxt-auth 15:06:04
i Building client...                                                        15:06:06
vite v4.1.3 building for production...
✓ 720 modules transformed.
.nuxt/dist/client/manifest.json                                  7.38 kB
.nuxt/dist/client/_nuxt/FullPageLoader.7e4914a9.css              0.17 kB │ gzip:   0.16 kB
.nuxt/dist/client/_nuxt/error-500.aa16ed4d.css                   1.95 kB │ gzip:   0.74 kB
.nuxt/dist/client/_nuxt/error-404.23f2309d.css                   3.63 kB │ gzip:   1.12 kB
.nuxt/dist/client/_nuxt/index.9cc2c039.css                       4.74 kB │ gzip:   1.05 kB
.nuxt/dist/client/_nuxt/request.00348271.css                     7.53 kB │ gzip:   1.51 kB
.nuxt/dist/client/_nuxt/default.ac5dfa01.css                     9.76 kB │ gzip:   2.17 kB
.nuxt/dist/client/_nuxt/_page_.c29dbab0.css                     15.03 kB │ gzip:   2.54 kB
.nuxt/dist/client/_nuxt/index.df6f269e.css                      23.64 kB │ gzip:   4.04 kB
.nuxt/dist/client/_nuxt/entry.126eb46b.css                     174.48 kB │ gzip:  26.70 kB
.nuxt/dist/client/_nuxt/_plugin-vue_export-helper.c27b6911.js    0.09 kB │ gzip:   0.10 kB
.nuxt/dist/client/_nuxt/composables.29a6900b.js                  0.10 kB │ gzip:   0.11 kB
.nuxt/dist/client/_nuxt/usePageTitle.7de6d82a.js                 0.16 kB │ gzip:   0.15 kB
.nuxt/dist/client/_nuxt/public.c458d5ed.js                       0.24 kB │ gzip:   0.20 kB
.nuxt/dist/client/_nuxt/index.3cd9a21e.js                        0.31 kB │ gzip:   0.25 kB
.nuxt/dist/client/_nuxt/FullPageLoader.36c164b0.js               0.31 kB │ gzip:   0.25 kB
.nuxt/dist/client/_nuxt/login.105fadad.js                        0.50 kB │ gzip:   0.34 kB
.nuxt/dist/client/_nuxt/logout.4c16151f.js                       0.61 kB │ gzip:   0.41 kB
.nuxt/dist/client/_nuxt/error-component.435f5ef8.js              1.26 kB │ gzip:   0.65 kB
.nuxt/dist/client/_nuxt/error-500.fcca766c.js                    1.97 kB │ gzip:   1.04 kB
.nuxt/dist/client/_nuxt/ProductType.e05146fa.js                  2.86 kB │ gzip:   1.01 kB
.nuxt/dist/client/_nuxt/en.170c0efa.js                           3.38 kB │ gzip:   1.54 kB
.nuxt/dist/client/_nuxt/de.0afc69a8.js                           3.76 kB │ gzip:   1.87 kB
.nuxt/dist/client/_nuxt/fr.28aaf853.js                           3.83 kB │ gzip:   1.82 kB
.nuxt/dist/client/_nuxt/error-404.4c05b4be.js                    5.94 kB │ gzip:   2.64 kB
.nuxt/dist/client/_nuxt/index.2da1f03f.js                       13.92 kB │ gzip:   5.22 kB
.nuxt/dist/client/_nuxt/default.8a1e6fff.js                     15.49 kB │ gzip:   5.29 kB
.nuxt/dist/client/_nuxt/_page_.24f10d78.js                      33.82 kB │ gzip:  10.65 kB
.nuxt/dist/client/_nuxt/request.0cd64a7b.js                     45.70 kB │ gzip:  13.45 kB
.nuxt/dist/client/_nuxt/index.60015acf.js                       76.21 kB │ gzip:  23.48 kB
.nuxt/dist/client/_nuxt/entry.9d40b3c0.js                      330.37 kB │ gzip: 119.98 kB
√ Client built in 6251ms                                                    15:06:12  
i Building server...                                                        15:06:12  
vite v4.1.3 building SSR bundle for production...
✓ 587 modules transformed.
.nuxt/dist/server/_nuxt/app-styles.67817251.mjs                           0.08 kB
.nuxt/dist/server/_nuxt/_page_-styles.397e3add.mjs                        0.08 kB     
.nuxt/dist/server/_nuxt/request-styles.08347e73.mjs                       0.08 kB     
.nuxt/dist/server/_nuxt/default-styles.4560f288.mjs                       0.08 kB     
.nuxt/dist/server/_nuxt/error-404-styles.a5c3f351.mjs                     0.08 kB     
.nuxt/dist/server/_nuxt/error-500-styles.6b5b5ff2.mjs                     0.08 kB     
.nuxt/dist/server/_nuxt/AppHeader-styles.1207cd42.mjs                     0.08 kB     
.nuxt/dist/server/_nuxt/UserAvatar-styles.6c0d2e41.mjs                    0.09 kB     
.nuxt/dist/server/_nuxt/ProductDataForm-styles.57ab83bc.mjs               0.09 kB     
.nuxt/dist/server/_nuxt/ProductDatesForm-styles.810d117b.mjs              0.09 kB     
.nuxt/dist/server/_nuxt/LanguageSelector-styles.7c10571b.mjs              0.09 kB     
.nuxt/dist/server/_nuxt/FeatureSwitchDebugger-styles.cd33625f.mjs         0.10 kB     
.nuxt/dist/server/styles.mjs                                              1.45 kB     
.nuxt/dist/server/_nuxt/composables-491adbd6.js                           0.16 kB     
.nuxt/dist/server/_nuxt/FeatureSwitchDebugger-styles-1.mjs-694d14d0.js    0.19 kB     
.nuxt/dist/server/_nuxt/_plugin-vue_export-helper-cc2b3d55.js             0.19 kB     
.nuxt/dist/server/_nuxt/LanguageSelector-styles-1.mjs-58671108.js         0.21 kB     
.nuxt/dist/server/_nuxt/_page_-styles-1.mjs-ce4630b5.js                   0.26 kB     
.nuxt/dist/server/_nuxt/default-styles-1.mjs-fd5f6b15.js                  0.26 kB     
.nuxt/dist/server/_nuxt/usePageTitle-ae0a6e95.js                          0.29 kB     
.nuxt/dist/server/_nuxt/FullPageLoader-styles-1.mjs-c842c86c.js           0.33 kB     
.nuxt/dist/server/_nuxt/UserAvatar-styles-1.mjs-8b1ba6fc.js               0.36 kB     
.nuxt/dist/server/_nuxt/AppHeader-styles-1.mjs-9cd6474f.js                0.46 kB     
.nuxt/dist/server/_nuxt/ProductDataForm-styles-1.mjs-af311bc9.js          0.48 kB     
.nuxt/dist/server/_nuxt/ProductDatesForm-styles-1.mjs-799fba4e.js         0.49 kB     
.nuxt/dist/server/_nuxt/public-7b62fa87.js                                0.78 kB     
.nuxt/dist/server/_nuxt/request-styles-1.mjs-b5ceb9a3.js                  0.95 kB     
.nuxt/dist/server/_nuxt/FullPageLoader-46ecd82d.js                        1.16 kB     
.nuxt/dist/server/_nuxt/app-styles-1.mjs-63bd16b3.js                      1.26 kB     
.nuxt/dist/server/_nuxt/index-d0ed4a13.js                                 1.34 kB     
.nuxt/dist/server/_nuxt/island-renderer-4a2d7cbe.js                       1.44 kB     
.nuxt/dist/server/_nuxt/logout-7d50c733.js                                1.57 kB     
.nuxt/dist/server/_nuxt/login-4a692021.js                                 1.66 kB     
.nuxt/dist/server/_nuxt/error-component-a412f908.js                       1.96 kB     
.nuxt/dist/server/_nuxt/error-500-styles-1.mjs-0a86f27a.js                2.11 kB     
.nuxt/dist/server/_nuxt/error-dev-styles-1.mjs-90bc7cbc.js                2.40 kB     
.nuxt/dist/server/_nuxt/error-500-cd59569f.js                             3.33 kB     
.nuxt/dist/server/_nuxt/error-404-styles-1.mjs-6ef6e240.js                3.80 kB     
.nuxt/dist/server/_nuxt/ProductType-b608b999.js                           4.71 kB     
.nuxt/dist/server/_nuxt/en-67d00a25.js                                    5.01 kB     
.nuxt/dist/server/_nuxt/de-9e9381ac.js                                    5.38 kB     
.nuxt/dist/server/_nuxt/fr-91d583fc.js                                    5.45 kB     
.nuxt/dist/server/_nuxt/error-404-1435de1f.js                             8.42 kB     
.nuxt/dist/server/_nuxt/index-63d9168c.js                                29.65 kB     
.nuxt/dist/server/_nuxt/default-4e4d8993.js                              47.37 kB     
.nuxt/dist/server/_nuxt/_page_-4466925c.js                               79.90 kB     
.nuxt/dist/server/_nuxt/index-153b37b2.js                               116.93 kB     
.nuxt/dist/server/_nuxt/request-dcd6482e.js                             148.89 kB     
.nuxt/dist/server/_nuxt/css-styles-1.mjs-a629272c.js                    173.40 kB     
.nuxt/dist/server/server.mjs                                            267.28 kB     
√ Server built in 3808ms                                                    15:06:16  
√ Generated public .output/public                                     nitro 15:06:16
i Building Nitro Server (preset: node-server)                         nitro 15:06:16
Export "getToken" 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/user/preferences.patch.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "getToken" 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/user/preferences.get.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "getToken" 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/utils/oauth.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "getServerSession" 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/logger.post.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
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/auth/[...].ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
√ Nitro server built                                                  nitro 15:06:31
  ├─ .output/server/package.json (2.06 kB) (739 B gzip)
  ├─ .output/server/index.mjs (607 B) (297 B gzip)
  ├─ .output/server/chunks/UserAvatar-styles.6c0d2e41.mjs.map (342 B) (221 B gzip)    
  ├─ .output/server/chunks/UserAvatar-styles.6c0d2e41.mjs (478 B) (287 B gzip)        
  ├─ .output/server/chunks/usePageTitle-ae0a6e95.mjs.map (365 B) (246 B gzip)
  ├─ .output/server/chunks/usePageTitle-ae0a6e95.mjs (285 B) (212 B gzip)
  ├─ .output/server/chunks/styles.mjs.map (1.07 kB) (332 B gzip)
  ├─ .output/server/chunks/styles.mjs (1.45 kB) (478 B gzip)
  ├─ .output/server/chunks/server.mjs.map (286 kB) (38.7 kB gzip)
  ├─ .output/server/chunks/server.mjs (240 kB) (57.8 kB gzip)
  ├─ .output/server/chunks/rollup/_virtual_head-static.mjs.map (111 B) (112 B gzip)   
  ├─ .output/server/chunks/rollup/_virtual_head-static.mjs (544 B) (336 B gzip)       
  ├─ .output/server/chunks/request-styles.08347e73.mjs.map (334 B) (219 B gzip)       
  ├─ .output/server/chunks/request-styles.08347e73.mjs (1.05 kB) (459 B gzip)
  ├─ .output/server/chunks/request-dcd6482e.mjs.map (137 kB) (17.7 kB gzip)
  ├─ .output/server/chunks/request-dcd6482e.mjs (149 kB) (20.1 kB gzip)
  ├─ .output/server/chunks/renderer.mjs.map (20.4 kB) (3.55 kB gzip)
  ├─ .output/server/chunks/renderer.mjs (16.5 kB) (5.04 kB gzip)
  ├─ .output/server/chunks/public-7b62fa87.mjs.map (862 B) (396 B gzip)
  ├─ .output/server/chunks/public-7b62fa87.mjs (829 B) (444 B gzip)
  ├─ .output/server/chunks/ProductType-b608b999.mjs.map (4.37 kB) (1.12 kB gzip)      
  ├─ .output/server/chunks/ProductType-b608b999.mjs (4.75 kB) (1.33 kB gzip)
  ├─ .output/server/chunks/ProductDatesForm-styles.810d117b.mjs.map (360 B) (226 B gzip)
  ├─ .output/server/chunks/ProductDatesForm-styles.810d117b.mjs (626 B) (322 B gzip)  
  ├─ .output/server/chunks/ProductDataForm-styles.57ab83bc.mjs.map (357 B) (225 B gzip)
  ├─ .output/server/chunks/ProductDataForm-styles.57ab83bc.mjs (617 B) (322 B gzip)   
  ├─ .output/server/chunks/preferences.patch.mjs.map (1.25 kB) (366 B gzip)
  ├─ .output/server/chunks/preferences.patch.mjs (1.72 kB) (744 B gzip)
  ├─ .output/server/chunks/preferences.get.mjs.map (1.11 kB) (355 B gzip)
  ├─ .output/server/chunks/preferences.get.mjs (1.6 kB) (689 B gzip)
  ├─ .output/server/chunks/node-server.mjs.map (120 kB) (8.01 kB gzip)
  ├─ .output/server/chunks/node-server.mjs (38.4 kB) (11.1 kB gzip)
  ├─ .output/server/chunks/metrics.get.mjs.map (206 B) (162 B gzip)
  ├─ .output/server/chunks/metrics.get.mjs (225 B) (169 B gzip)
  ├─ .output/server/chunks/logout-7d50c733.mjs.map (944 B) (426 B gzip)
  ├─ .output/server/chunks/logout-7d50c733.mjs (1.92 kB) (800 B gzip)
  ├─ .output/server/chunks/login-4a692021.mjs.map (1.11 kB) (482 B gzip)
  ├─ .output/server/chunks/login-4a692021.mjs (2.01 kB) (859 B gzip)
  ├─ .output/server/chunks/logger.post.mjs.map (1.79 kB) (551 B gzip)
  ├─ .output/server/chunks/logger.post.mjs (1.96 kB) (874 B gzip)
  ├─ .output/server/chunks/LanguageSelector-styles.7c10571b.mjs.map (360 B) (227 B gzip)
  ├─ .output/server/chunks/LanguageSelector-styles.7c10571b.mjs (351 B) (201 B gzip)  
  ├─ .output/server/chunks/island-renderer-4a2d7cbe.mjs.map (1.15 kB) (506 B gzip)    
  ├─ .output/server/chunks/island-renderer-4a2d7cbe.mjs (1.79 kB) (779 B gzip)        
  ├─ .output/server/chunks/index-d0ed4a13.mjs.map (896 B) (409 B gzip)
  ├─ .output/server/chunks/index-d0ed4a13.mjs (1.69 kB) (745 B gzip)
  ├─ .output/server/chunks/index-63d9168c.mjs.map (32.8 kB) (6.45 kB gzip)
  ├─ .output/server/chunks/index-63d9168c.mjs (29.7 kB) (7.08 kB gzip)
  ├─ .output/server/chunks/index-153b37b2.mjs.map (125 kB) (21.3 kB gzip)
  ├─ .output/server/chunks/index-153b37b2.mjs (117 kB) (23.5 kB gzip)
  ├─ .output/server/chunks/health.get.mjs.map (188 B) (155 B gzip)
  ├─ .output/server/chunks/health.get.mjs (173 B) (151 B gzip)
  ├─ .output/server/chunks/FullPageLoader-46ecd82d.mjs.map (1.05 kB) (467 B gzip)     
  ├─ .output/server/chunks/FullPageLoader-46ecd82d.mjs (1.13 kB) (557 B gzip)
  ├─ .output/server/chunks/fr-91d583fc.mjs.map (3.96 kB) (939 B gzip)
  ├─ .output/server/chunks/fr-91d583fc.mjs (5.96 kB) (2.22 kB gzip)
  ├─ .output/server/chunks/FeatureSwitchDebugger-styles.cd33625f.mjs.map (375 B) (230 B gzip)
  ├─ .output/server/chunks/FeatureSwitchDebugger-styles.cd33625f.mjs (339 B) (194 B gzip)
  ├─ .output/server/chunks/error-component-a412f908.mjs.map (2.35 kB) (809 B gzip)    
  ├─ .output/server/chunks/error-component-a412f908.mjs (2.04 kB) (897 B gzip)        
  ├─ .output/server/chunks/error-500.mjs.map (1.04 kB) (378 B gzip)
  ├─ .output/server/chunks/error-500.mjs (4.26 kB) (1.82 kB gzip)
  ├─ .output/server/chunks/error-500-styles.6b5b5ff2.mjs.map (340 B) (220 B gzip)     
  ├─ .output/server/chunks/error-500-styles.6b5b5ff2.mjs (2.22 kB) (864 B gzip)       
  ├─ .output/server/chunks/error-500-cd59569f.mjs.map (1.7 kB) (612 B gzip)
  ├─ .output/server/chunks/error-500-cd59569f.mjs (3.61 kB) (1.55 kB gzip)
  ├─ .output/server/chunks/error-404-styles.a5c3f351.mjs.map (340 B) (220 B gzip)     
  ├─ .output/server/chunks/error-404-styles.a5c3f351.mjs (3.92 kB) (1.25 kB gzip)     
  ├─ .output/server/chunks/error-404-1435de1f.mjs.map (6.73 kB) (1.63 kB gzip)        
  ├─ .output/server/chunks/error-404-1435de1f.mjs (8.73 kB) (2.85 kB gzip)
  ├─ .output/server/chunks/en-67d00a25.mjs.map (3.94 kB) (864 B gzip)
  ├─ .output/server/chunks/en-67d00a25.mjs (5.35 kB) (1.94 kB gzip)
  ├─ .output/server/chunks/default-styles.4560f288.mjs.map (333 B) (221 B gzip)       
  ├─ .output/server/chunks/default-styles.4560f288.mjs (372 B) (229 B gzip)
  ├─ .output/server/chunks/default-4e4d8993.mjs.map (44.5 kB) (7.05 kB gzip)
  ├─ .output/server/chunks/default-4e4d8993.mjs (47.4 kB) (8.12 kB gzip)
  ├─ .output/server/chunks/de-9e9381ac.mjs.map (3.96 kB) (927 B gzip)
  ├─ .output/server/chunks/de-9e9381ac.mjs (5.83 kB) (2.28 kB gzip)
  ├─ .output/server/chunks/composables-491adbd6.mjs.map (291 B) (217 B gzip)
  ├─ .output/server/chunks/composables-491adbd6.mjs (210 B) (174 B gzip)
  ├─ .output/server/chunks/client.manifest.mjs.map (7.08 kB) (827 B gzip)
  ├─ .output/server/chunks/client.manifest.mjs (9.1 kB) (1.18 kB gzip)
  ├─ .output/server/chunks/AppHeader-styles.1207cd42.mjs.map (339 B) (222 B gzip)     
  ├─ .output/server/chunks/AppHeader-styles.1207cd42.mjs (577 B) (332 B gzip)
  ├─ .output/server/chunks/app-styles.67817251.mjs.map (322 B) (210 B gzip)
  ├─ .output/server/chunks/app-styles.67817251.mjs (1.35 kB) (502 B gzip)
  ├─ .output/server/chunks/api.mjs.map (5.19 kB) (958 B gzip)
  ├─ .output/server/chunks/api.mjs (4.34 kB) (1.41 kB gzip)
  ├─ .output/server/chunks/_plugin-vue_export-helper-cc2b3d55.mjs.map (454 B) (273 B gzip)
  ├─ .output/server/chunks/_plugin-vue_export-helper-cc2b3d55.mjs (254 B) (200 B gzip)
  ├─ .output/server/chunks/_page_.get.mjs.map (17.8 kB) (4.08 kB gzip)
  ├─ .output/server/chunks/_page_.get.mjs (17.2 kB) (4.2 kB gzip)
  ├─ .output/server/chunks/_page_-styles.397e3add.mjs.map (330 B) (217 B gzip)        
  ├─ .output/server/chunks/_page_-styles.397e3add.mjs (366 B) (246 B gzip)
  ├─ .output/server/chunks/_page_-4466925c.mjs.map (78.8 kB) (13.3 kB gzip)
  ├─ .output/server/chunks/_page_-4466925c.mjs (80.3 kB) (14.9 kB gzip)
  ├─ .output/server/chunks/_..._.mjs.map (605 B) (260 B gzip)
  └─ .output/server/chunks/_..._.mjs (1.15 kB) (541 B gzip)
Σ Total size: 6 MB (1.38 MB gzip)
√ You can preview this build using node .output/server/index.mjs
BracketJohn commented 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!

moussaclarke commented 1 year ago

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

BracketJohn commented 1 year ago

Thanks for the reproduction - will have a look into it 💯

moussaclarke commented 1 year ago

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.

moussaclarke commented 1 year ago

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.

moussaclarke commented 1 year ago

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.

mttzzz commented 4 months ago

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:    -
------------------------------
phoenix-ru commented 3 months ago

@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