nuxt-open-fetch
nuxt-open-fetch copied to clipboard
Environment variables don't work
Environment
- Operating System: Darwin
- Node Version: v20.7.0
- Nuxt Version: 3.12.4
- CLI Version: 3.12.0
- Nitro Version: 2.9.7
- Package Manager: [email protected]
- Builder: -
- User Config: app, robots, auth, components, css, devServer, devtools, eslint, modules, openFetch, router, runtimeConfig, sourcemap, srcDir, experimental, vite, compatibilityDate
- Runtime Modules: @nuxt/[email protected], @nuxtjs/[email protected], [email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], @vueuse/[email protected], @sidebase/[email protected], [email protected]
- Build Modules: -
Reproduction
https://stackblitz.com/edit/github-pljepz?file=nuxt.config.ts
Describe the bug
Env variables are never read on dev start
Additional context
No matter how/where I declare the variables, or the openfetch options (in the root, or in public config), the env vars are never used.
Logs
No response
The only way to get it to work is to manually reference the env variable in the config, like this:
openFetch: {
disableNuxtPlugin: true,
openAPITS: {
alphabetize: true,
exportType: true,
},
clients: {
rvezy: {
schema: process.env.NUXT_PUBLIC_OPEN_FETCH_FOO_SCHEMA,
baseURL: process.env.NUXT_PUBLIC_OPEN_FETCH_FOO_BASE_URL,
},
},
},
However, this doesn't work when type checking...
@enkot Any change you could look into the open issues?
Currently the module seems very useful, but it can't be used in production because the config part doesn't properly work (yet). Would be more than happy to assist btw.
After digging more, the issue is that the documentation around config is wrong.
The only way to sort of make this work is by defining openFetch at the root of the config, not in runtimeConfig and hardcode the baseULR as: process.env.NUXT_OPEN_FETCH_RENTALS_BASE_URL || 'http://localhost/fallback-url'
Hi @TheDutchCoder,
Added not to the docs - https://github.com/enkot/nuxt-open-fetch/commit/4d8d7dedc782e976325871f7aade85b1bb2d21a6