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

Adding multiple times a same module in nuxt.config.js is not working #7605

Closed
gtnsimon opened this issue Jun 25, 2020 · 2 comments
Closed

Adding multiple times a same module in nuxt.config.js is not working #7605

gtnsimon opened this issue Jun 25, 2020 · 2 comments

Comments

@gtnsimon
Copy link

Version

v2.13.1

Reproduction link

https://codesandbox.io/s/nuxt-module-issue-not-working-k40t5

Steps to reproduce

  • Fork the CodeSandbox (seems to be required for experimental features used by codesandbox-nuxt)
  • Go to Server Control Panel
  • Click "Restart Server" in Control Container
  • Look at Terminal under the Browser Preview after the line :
    > Sandbox Container: Sandbox <xxxxx> started
    yarn run v1.22.4
    [...]
    

What is expected ?

The foo module should be print twice the console.log defined in /modules/foo/index.js because nuxt.config.js contains two times '/modules/foo' in options.modules, with different modules' options. See Additional comments for the output of the console.log.

What is actually happening?

The foo moduleprints only once the console.log.

Additional comments?

I've added a "foo" module that do a simple console.log for demo purpose. I expect it to be called twice, but it is not the case.

Reproduction link details

The console.log output for the NOT WORKING CodeSandbox (the one in the "Reproduction link") is :

[nuxt-v2.13.1] foo module being added, options: {
  foo: 'bar'
}

A working example

Here found a WORKING CodeSandbox using nuxt@2.12.2 : https://codesandbox.io/s/nuxt-module-issue-working-lnzpc

The console.log output for the WORKING CodeSandbox is :

[nuxt-v2.12.2] foo module being added, options: {
  foo: 'bar'
}

[nuxt-v2.12.2] foo module being added, options: {
  bar: 'baz'
}

Real use case

The real use case is a module copying files base on a template. The copy is done using addTemplate with the same source file to a different destination and options (based on module options). Each time the module is referenced in the nuxt.config.js, I need to execute the module in order to generate needed files.

This bug report is available on Nuxt community (#c10845)
@ghost ghost added the cmty:bug-report label Jun 25, 2020
@pi0 pi0 closed this as completed in d0056fb Jun 25, 2020
@pi0 pi0 reopened this Jun 25, 2020
@pi0
Copy link
Member

pi0 commented Jun 25, 2020

Hi @gtnsimon. I've added fix to avoid breaking change (d0056fb) will be released with next patch release to only warn.

You can import module to workaround regression and avoid error:

import foo from './modules/foo'

export default {
  modules: [
    [foo, { foo: 'bar' }],
    [foo, { bar: 'baz' }]
  ]
}

But I would highly recommend instead, supporting something like templates: [] option so that module can handle multiple copies in one executation.

@gtnsimon
Copy link
Author

Hi @pi0. Thank you for the tip on the use case. I'll refactor my code to fit to the new version, I wasn't aware on bests practices on how modules should be added to nuxt.config.js.

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