https://codesandbox.io/s/nuxt-module-issue-not-working-k40t5
log
> Sandbox Container: Sandbox <xxxxx> started
yarn run v1.22.4
[...]
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.
The foo moduleprints only once the console.log.
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.
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'
}
Here found a WORKING CodeSandbox using [email protected] : 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'
}
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.
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.
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.