Skip to content

validate config values of a module in setup #26858

Answered by dsvgl
jonasem asked this question in Questions
Discussion options

You must be logged in to vote

Ok. I got it working: https://stackblitz.com/edit/github-pgdfdr?file=src%2Fmodule.ts
run these commands:

npm install
npm run dev:prepare
npm run dev

I think the problem is that the specially named env vars mentioned here don't seem to work in the build step.

So, if having this in nuxt.config:

runtimeConfig: {
  moduleNameFoo: '',
},

Then staring your app via NUXT_MODULE_NAME_FOO=something npm run dev. Logging out nuxt.options.runtimeConfig.moduleNameFoo inside the module one can see that it's just that (same) empty string.

Doing this will make the var present for the module:

runtimeConfig: {
  moduleNameFoo: process.env.NUXT_MODULE_NAME_FOO || '',
},

This behavior makes sense. The automa…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@dsvgl
Comment options

Answer selected by jonasem
@jonasem
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants