nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

nuxt generate execute nuxt.config.js twice when set target=static

Open zcqno1 opened this issue 2 years ago • 3 comments

Versions

  • nuxt: v2.15.7
  • node: v12.14.0

Reproduction

image

Steps to reproduce

  1. set target: 'static' in nuxt.config.js
  2. add log in nuxt.config.js just under the module: console.log('hello')
  3. build with nuxt generate
  4. the shell would show two hello

What is Expected?

nuxt.config.js only executes once.

What is actually happening?

https://github.com/nuxt/nuxt.js/blob/853439ddf945b6ee358d5912e6e5a68009633c27/packages/cli/src/commands/generate.js#L71-L75

https://github.com/nuxt/nuxt.js/blob/ab1c6cb442c9418128c85ad2cb14ed162af44933/packages/cli/src/utils/generate.js#L130-L131

ensureBuild() and generate() both call getNuxt() which calls the cmd.getNuxtConfig(). getNuxtConfig method calls loadNuxtConfig() later, which would clear the require cache before loading nuxt.config.js. As a result, nuxt.config.js would run twice.

zcqno1 avatar Dec 01 '21 14:12 zcqno1

Also happening to me, as I am trying to bump up from Nuxt 2.14.X to 2.15:

  • Nuxt: v2.15.8
  • Node: v14.17.1

It is also doubling all calls to nuxt.hooks and running the modules and build modules twice (those using "generate.before" in my case)

nachoadjust avatar Jan 06 '22 14:01 nachoadjust

Thanks for your contribution to Nuxt! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

stale[bot] avatar Apr 16 '22 09:04 stale[bot]

This should open again

juanjcardona13 avatar Jan 29 '23 01:01 juanjcardona13