nuxt / nuxt/bridge

nuxt.options._layers is not iterable in v3.0.0

Open
#1,067 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

upstream workaround available
Dominant language
TypeScript
Stars
285
Forks
33
Avg merge
22h 38m
Merged PRs (30d)
3

Description

Environment

  • Operating System: Linux
  • Node Version: v20.8.1
  • Nuxt Version: 2.17.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.14.1
  • Builder: webpack
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Edit currying-tdd-4qddcj

The error only occurs in production after running :

yarn build
yarn start
Describe the bug

I am in the process of updating a module in our company from v3.0.0-rc.4 to v3.0.0

We're not using nitro and vite yet, as we still have some work to do.

Our module installs other modules using installModule function from @nuxt/kit.

The following error occurs when launching the server after a production build :

yarn run v1.22.19
$ nuxt2 start

 ERROR  nuxt.options._layers is not iterable                        7:37:51 PM

  at installModule (node_modules/@nuxt/kit/dist/index.mjs:2409:32)

I traced the error back to its source

If I understand correctly,

  • Version v3.0.0-rc.4 uses version v3.8.2 of @nuxt/kit
  • Version v3.0.0 uses version v3.9.1 of @nuxt/kit.
  • The installModule function in v3.9.1 depends on the contents of the nuxt.options._layers property. L19
  • The nuxt.options._layers property is mocked by @nuxt/bridge but only in dev environment or during the build process. L61
  • This is the reason why the nuxt.options._layers property is undefined when the server is started.

Proposed solution:

  • We need to mock _layers for nitro and auto-imports outside the buildModules function.
  • This solves the issue locally
Additional context

No response

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/bridge/module.cjs at the linked _layers mock and packages/kit/src/module/install.ts at installModule. Reproduce the production path with yarn build followed by yarn start, then verify that the server starts without the nuxt.options._layers error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.