fix(build): preserve getOptions in CJS wrapper #421
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello again @danielroe,
I started my day with a warning from
@nuxtjs/sitemap
about@nuxtjs/i18n
options not being available.@nuxtjs/sitemap
trying to access the options of@nuxtjs/i18n
usingnuxtModule.getOptions
getOptions
method (added bydefineNuxtModule
), it's lost in the CJS wrapper@nuxt/module-builder
only preservesmeta
andgetMeta
, but notgetOptions
(i guess)More details :
I investigated the warning and found its source in
@nuxtjs/sitemap
at https://github.com/nuxt-modules/sitemap/blob/main/src/module.ts#L219, which leads to https://github.com/nuxt-modules/sitemap/blob/f52cafd726e2c5a7ebf8f768eda5d0f9befac9cc/src/util/kit.ts#L37.The issue occurs when
@nuxtjs/sitemap
tries to use@nuxtjs/i18n
options:nuxtModule.getOptions
is undefined (wherenuxtModule
is@nuxtjs/i18n
), resulting in no return value fromnuxtModule.getOptions(inlineOptions, nuxt)
.The root cause is in the module loading process at https://github.com/nuxt/nuxt/blob/7177e81442559fee574e9460b4d76a780bb98211/packages/kit/src/module/install.ts#L85, where
getOptions
is not being preserved in the CJS wrapper.Looking at
module.cjs
from@nuxtjs/i18n
,getOptions
is indeed missing. I tested by manually adding it to my node_modules and it all work, no warning anymore from @nuxtjs/sitemap :I discovered that this part was implemented using this package, so here I am, proposing an update to build.ts.
I only started looking into this today, so there's a chance I might be mistaken. The issue might not be here and could be related to
@nuxtjs/i18n
or@nuxtjs/sitemap
.@harlan-zw , this might interest you. I'm using version
6.1.4
of@nuxtjs/sitemap