Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadConfig makes array type item duplicated. #13532

Closed
higuaifan opened this issue Mar 20, 2022 · 2 comments
Closed

loadConfig makes array type item duplicated. #13532

higuaifan opened this issue Mar 20, 2022 · 2 comments
Assignees

Comments

@higuaifan
Copy link

higuaifan commented Mar 20, 2022

Environment


  • Operating System: Darwin
  • Node Version: v16.14.0
  • Nuxt Version: 3.0.0
  • Package Manager: pnpm@6.32.3
  • Builder: vite
  • User Config: extensions, modules
  • Runtime Modules: ./modules/markdown
  • Build Modules: -

Reproduction

I don't think it might be necessary.

Describe the bug

if my nuxt.config.ts like this:

import { defineNuxtConfig } from 'nuxt3';

export default defineNuxtConfig({
  extensions:['.md'],
  modules:[
    './modules/markdown'
  ],
})

in loadNuxtConfig, after run loadConfig,nuxtConfig will like this:

{
  "extensions": [
    ".md",
    ".md"
  ],
  "modules": [
    "./modules/markdown",
    "./modules/markdown"
  ],
}

I believe it is a bug .. or this is a new feature (I don't know much about individual config layers for extending)?


in this line used loadConfig ,
https://github.com/nuxt/framework/blob/53fbca77d4b84ac9b8eadd582d7afbbbc5819fa1/packages/kit/src/loader/config.ts#L3
and c12 is upgrade to ^0.2.0 , support individual config layers for extending.
https://github.com/unjs/c12/blob/8808f3793875cf862326163196087cc68c75dae3/src/loader.ts#L99-L125

 const baseLayers = [
    opts.overrides && { config: opts.overrides, configFile: undefined, cwd: undefined },
    { config, configFile: opts.configFile, cwd: opts.cwd },
    opts.rcFile && { config: configRC, configFile: opts.rcFile }
  ].filter(l => l && l.config)

  // Allow extending
  if (opts.extend) {
    await extendConfig(r.config, opts)
    r.layers = [
      ...baseLayers,
      ...r.config._layers
    ]
    delete r.config._layers
    r.config = defu(
      r.config,
      ...r.layers.map(e => e.config)
    ) as T
  }

  // Apply defaults
  if (opts.defaults) {
    r.config = defu(r.config, opts.defaults) as T
  }

  // Return resolved config
  return r

baseLayers includes config and then defu config to r.config...I think the problem might be here..


anyway.. It will makes module load twice..

Additional context

No response

Logs

No response

@pi0
Copy link
Member

pi0 commented Mar 21, 2022

Thanks for the detailed issue @higuaifan. This issue should be resolved by unjs/c12@367cbf8. Can you please try upgrading using npn nuxi upgrade --force?

@higuaifan
Copy link
Author

Thanks for the detailed issue @higuaifan. This issue should be resolved by unjs/c12@367cbf8. Can you please try upgrading using npn nuxi upgrade --force?

Yeah! It works ! Thanks for resolve!

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants