nuxt: Circular dependency in nuxt with nitropack

Environment


  • Operating System: Windows_NT
  • Node Version: v16.17.0
  • Nuxt Version: 3.1.2
  • Nitro Version: 2.1.1
  • Package Manager: yarn@1.22.18
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

and stackblitz

Reproduction

https://stackblitz.com/edit/nuxt-starter-kqf57y?file=README.md

Describe the bug

Hi 👋 ! Nuxt build in 3.1.2 logs a warning about circular dependency

Additional context

No response

Logs

`
Export "useNitroApp" of module "node_modules/nitropack/dist/runtime/app.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 "node_modules/nuxt/dist/core/runtime/nitro/renderer.mjs" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 43 (17 by maintainers)

Most upvoted comments

Thanks! Can be reproduced with a clean starter running npm build

Indeed, it’s still present in 3.2.0, but it should be resolved in the edge channel, or in the next release.

Did you guys try this? https://github.com/nuxt/nuxt/pull/22785#issuecomment-1697171634

import { useNitroApp } from '#internal/nitro/app'

Thank you for clarification 🙂

Hi @manniL My code was working fine from early versions of Nuxt3 up to v3.1.2. The warning message started after updating to Nuxt 3.2.0 and I think I’m not the only one. If some more people could verify that would be great!

Fix is released in nitro 2.2.1 but nuxt 3.2.0 use nitro 2.2.0

Nuxt 3.2.0 dependency use "nitropack": "^2.2.1"

"node_modules/nuxt": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/nuxt/-/nuxt-3.2.0.tgz", "integrity": "sha512-8jAYyjU1Ht+MXPLLDIdIUmV56KiI0g7KusKwzvqn+vlzyCNtSHg2W/VBCGw5QWplb/MXruogcMl2sDenlQRZFg==", "dev": true, "dependencies": { [..] "nitropack": "^2.2.1", "nuxi": "3.2.0", [..] },

  • Operating System: Windows_NT
  • Node Version: v19.4.0
  • Nuxt Version: 3.2.0
  • Nitro Version: 2.2.1
  • Package Manager: npm@9.4.2
  • Builder: vite
  • User Config: pages, css, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.9-27926914.891e694
  • Build Modules: -
 WARN  Export "useNitroApp" of module "node_modules/nitropack/dist/runtime/app.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 "node_modules/nuxt/dist/core/runtime/nitro/renderer.mjs" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

I continue to get the message

Nuxt project info: 09:03:47


  • Operating System: Windows_NT
  • Node Version: v19.4.0
  • Nuxt Version: 3.1.2
  • Nitro Version: 2.2.1
  • Package Manager: npm@9.4.2
  • Builder: vite
  • User Config: pages, css, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@8.0.0-beta.9-27926914.891e694
  • Build Modules: -

@fabianwohlfart This indeed suppressed the error

please open a new issue with reproduction 🙏🏼

I can reproduce with Nuxt 3.10.1, Nitropack 2.8.1

Export "useNitroApp" of module "node_modules/nitropack/dist/runtime/app.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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/index.ts" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

Here is the link to reproduction: https://codesandbox.io/p/sandbox/quirky-lovelace-pd9l7w

Yes this can be closed out again. Sorry for the confusion

Ah I found the issue. We had a config that was being imported into our core layer’s app config. That config was importing composable functions. When I commented those out the error went away. I’m going to rework the config so that we don’t directly import those composables into the config. Just a casualty of converting a lot of JSON based configs into one main app.config.ts file.

Is there a recent minimal reproduction based on either Nuxt or Nitro latest versions?

Given the detailed description, I reopen this issue.

I’m seeing a similar circular dependency in Nuxt 3.8.2 with Nitro 2.8.1 (and Nuxt 3.8.0 before I tried an update) where useRuntimeConfig is being flagged.

 ERROR  [worker reload] [worker init] Cannot access '_sharedRuntimeConfig' before initialization                                                             12:33:34 PM

  at useRuntimeConfig (node_modules/nitropack/dist/runtime/config.mjs:13:5)
  at <anonymous> (node_modules/nitropack/dist/runtime/route-rules.mjs:11:16)
  at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

And these errors when I run the build command

Export "useRuntimeConfig" of module "node_modules/nitropack/dist/runtime/config.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 "node_modules/nuxt/dist/core/runtime/nitro/paths.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "getRouteRules" of module "node_modules/nitropack/dist/runtime/route-rules.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 "node_modules/nuxt/dist/core/runtime/nitro/renderer.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "useRuntimeConfig" of module "node_modules/nitropack/dist/runtime/config.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 "node_modules/nuxt/dist/core/runtime/nitro/renderer.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.
Export "useRuntimeConfig" of module "node_modules/nitropack/dist/runtime/config.mjs" was reexported through module "node_modules/nitropack/dist/runtime/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 ".nuxt/dist/server/server.mjs" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

At first, I suspected this was due to a use of useRuntimeConfig in a Nitro hook plugin. But I rewrote that plugin to remove the use of the runtime config, and it was still being flagged in the build and when trying to run dev.

Thanks for the report. Raised https://github.com/nuxt/nuxt/pull/22785.

Fix is released in nitro 2.2.1 but nuxt 3.2.0 use nitro 2.2.0

There is similar issue raised at nuxt content repo

this might be related, i’m using 3.1.2 while @Barbapapazes is using 3.1.1. I tried to use useHead in a component and then build a project but this did not trigger the warning with useHead