nuxt-community / dotenv-module Goto Github PK
View Code? Open in Web Editor NEWLoads your .env file into your application context
License: MIT License
Loads your .env file into your application context
License: MIT License
I've follow the instructions to add the dotenv module.
When I run npm run dev
I'm getting the following error:
This dependency was not found:
To install it, you can run: npm install --save fs
Digging into this npm package its seems to be a security-holder package.
How to solve the error?
Currently, if the only
option is specified with an empty array, default logic is used and all values are placed into context.env
and thus provided to the client.
I think that an empty array should signal that I do not want anything copied into context.env
. If I do not specify an only
option/array at all, I would expect the default behavior to apply and all values would be placed into context.env
.
As a workaround, I specify a name in the array that doesn't correspond to any key:
['@nuxtjs/dotenv', { only: ['nothing'] }],
Related, I agree with this comment on #7 that there should be a warning that all values are available on the client unless only
is used.
This configuration
['@nuxtjs/dotenv', { only: [] }],
results in nothing in .env
going into context.env
.
Hello @JulienTant,
This is release in code since months (3e26963)
but not on npm… (dist folder is not up to date) "version": "1.1.1"
{
modules: [
['@nuxtjs/dotenv', { filename: '.env.prod' }],
]
}
Could you please update repositories.
Regards
I'm coming to nuxt from vue-cli and vue-cli has a way of loading multiple .env files which I found very logical and convenient
See docs here: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables
And image explaining the gist of it:
I would like to do the same with nuxt now... so .env would always be loaded, then depending on the environment (dev, staging, production) it would optionally also load .env.[environment]
And furthermore it could also load .env.local and .env.[environment].local (.local files are by default ignored by .git)
The .local bit is not so crucial but the ability to load .env + .env.[environment] I found very useful. Of course any values in .env.[environment] would overwrite any identical values in .env
Can I achieve this with nuxt's dotenv-module?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These problems occurred while renovating this repository. View logs.
Warning
These dependencies are deprecated:
Datasource | Name | Replacement PR? |
---|---|---|
npm | @nuxtjs/module-test-utils |
|
npm | codecov |
|
npm | standard-version |
These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.
@commitlint/cli
, @commitlint/config-conventional
, @types/jest
, dotenv
, eslint
, eslint-plugin-jest
)These updates are pending. To force PRs open, click the checkbox below.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@commitlint/cli
, @commitlint/config-conventional
).github/workflows/ci.yaml
actions/checkout v4
actions/setup-node v4
package.json
consola ^3.2.3
dotenv ^8.2.0
@commitlint/cli ^18.4.2
@commitlint/config-conventional ^18.4.2
@nuxtjs/eslint-config ^12.0.0
@nuxtjs/module-test-utils ^1.6.3
@types/jest ^29.5.8
codecov ^3.8.3
eslint ^8.53.0
eslint-plugin-jest ^27.6.0
husky ^8.0.3
jest ^29.7.0
nuxt-edge ^2.17.2-28284499.5674f49
standard-version ^9.5.0
Currently this module expects that the .env
file to live in the root of the NuxtJS project. I have a usecase where I wish for the .env
file to live in another location so it can be shared among multiple projects.
As such, it would be ideal if the module accepted a path option.
PR incoming.
Hello.
.env.dev file is not working in nuxt plugin.
i created .env.dev file and run script "nuxt --dotenv .env.dev".
print env variable in my custom nuxt plugin.
console.log(process.env) #output :: {}
But .env file is working.
i have try :
private_key="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAAS....."
or
private_key:-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAAS...
or
private_key:'-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAAS....'
but result is Certificate object must contain a string "private_key" property.
I'm trying to make a Nuxt layer, with a demo folder to extend the base/layer code.
So, to launch the project, yarn dev
is equivalent to nuxt dev demo
Env vars from .env file seems to not be read. Console logs returns undefined on nuxt.config.ts
of the layer.
If I launch the project without targeting the demo folder (nuxt dev
), everything works.
https://stackblitz.com/edit/github-yzyan4?file=package.json,nuxt.config.ts
In our team, we would like to use .env
file for local development. But it won't be committed to git. And while deploying it will take env variables from server. Right now when I add .env to .gitignore and when I try to build it from where, it throws an error saying that .env file is not found
Thanks a lot for those remarkable jobs you've done!
Just wander if there is a plan for nuxt3?
(just have a try on nuxt3: not work but without any errors in both console and terminal)
the environment variables are not defined at the beginning. I am using the nuxtjs / axios module where I configure:
baseURL: process.env.API_URL,
browserBaseURL: process.env.API_URL_BROWSER
with this config an error occurs:
TypeError: Cannot read property 'substr' of undefined
at ModuleContainer.nuxtAxios (/home/javier/vms/twobvm/projects/cominghouse/node_modules/@nuxtjs/axios/lib/index.js:38:46)
thank you!
VUE_APP_A=A
VUE_APP_AB=$VUE_APP_A/B
VUE_APP_A=A
VUE_APP_AB=A/B
VUE_APP_A=A
VUE_APP_AB=$VUE_APP_A/B
This works fine in vue-cli SPA, but doesn't work in nuxt. I assume they both use the same library, but nuxt is missing something.
https://github.com/beardedpayton/paytonburdette.com-v2
Install module
npm i nuxtjs/dotenv
** cant include the @ symbol here, it thinks I'm trying to tag a user in the issue
Require module in nuxt.config.js
require('dotenv').config()
Add module to modules array in nuxt.config.js
modules: ["@nuxtjs/dotenv"]
Use "module in codebase with process.env.ENV_VAR_NAME
Works as expected locally. I can read from my .env file fine.
When deploying to Netlify and using build environment variables, I should be able to read from those variables within my project.
I cannot read variables from my build environment variables established with Netlify. I can only read from them if a .env file is present.
Hello,
Sorry to interrupt here but I really can not manage to achieve a simple thing (read process.env)
#1 - Only way I can read what's in my .env file is by
require('dotenv').config()
in nuxt.config.js
When I'm adding it as a module, it doesn't find anything even if .env is at the root...
#2 still in nuxt.config.js I define :
env: {
test: process.env.TEST,
},
#3
In server/index.js I define :
const test = process.env.test
And it's always undefined...
I've tried a lot and a lot of thing but I think I'm missing something here. Any help will be really appreciate !
thanks !
output of .env file vars array
empty object "{}"
nuxt version "nuxt": "^2.0.0",
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (@nuxtjs)
In most places where dotenv is used system env vars override the dotenv vars, however dotenv-module does the exact opposite, swapping this around would give the expected result when using systemvars: true
https://couldnt-get-codesandbox-to-work
I'm using yarn 1.17.3 and dotenv-module 1.3.0. (problem also occurs on npm)
Install those and try using systemvars: true
. No vars will be loaded.
This is what I get when building the dist/index.js
file myself, which is OK:
if (options.systemvars) {
Object.keys(process.env).map(function (key) {
if (!(key in envConfig)) {
envConfig[key] = process.env[key];
}
});
}
But this is what I get when installing the package:
if (options.systemvars) {
Object.keys(process.env).map(function (key) {
if (!key in envConfig) {
envConfig[key] = process.env[key];
}
});
}
The condition always returns false and no vars are loaded.
Hello!
I've been unable to deploy to Netlify when using the plugin.
modules: [
['@nuxtjs/dotenv']
]
Netlfiy Error log when using the module
Netfliy log for successful deployment
I've tried a whole bunch of different configurations inside nuxt.config.js
but could'nt get anything to work. I don't get the issue when I generate the static site locally just when using Netlify. I have spoke to their support and they can't see the issue. I am wondering if its to do with the NPM WARN
about missing optional dependencies? Let me know if you need anymore info!
🚨 You need to enable Continuous Integration on all branches of this repository. 🚨
To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.
Since we did not receive a CI status on the greenkeeper/initial
branch, we assume that you still need to configure it.
If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/
.
We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.
Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial
branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.
Hi,
I tried to use nuxt-dotenv with fileaname custom options like that:
modules: [
['@nuxtjs/dotenv', {
filename: '.env.dev',
}],
],
It's working fine in my app but not in my nuxt-config.js
I import dotenv at the top:
require('dotenv').config()
Before that I had to add the dotenv dependency to my package.json.
But the custom .env file wasn't read. Only .env is working.
Is there also support for nuxt3?
I don't think the default nuxt3 way is very convenient because it also requires modifying nuxt.config.ts when the env variables are required on the client side.
https://codesandbox.io/s/awesome-sanderson-vijy1
console.log server Terminal
/home | fetch() | from server
/home | fetch() | process.env.TEST1 TEST1
/home | fetch() | context.env.TEST1 undefined
/home | fetch() | process.env.TEST2 TEST2
/home | fetch() | context.env.TEST2 TEST2
/home | fetch() | process.env.TEST3 undefined
/home | fetch() | context.env.TEST3 undefined
console.log client Console (toggle route '/about' <> '/')
/home | fetch() | from client
/home | fetch() | process.env.TEST1 undefined
/home | fetch() | context.env.TEST1 undefined
/home | fetch() | process.env.TEST2 TEST2
/home | fetch() | context.env.TEST2 TEST2
/home | fetch() | process.env.TEST3 undefined
/home | fetch() | context.env.TEST3 undefined
console.log server Terminal
/home | fetch() | from server
/home | fetch() | process.env.TEST1 undefined
/home | fetch() | context.env.TEST1 undefined
/home | fetch() | process.env.TEST2 TEST2
/home | fetch() | context.env.TEST2 TEST2
/home | fetch() | process.env.TEST3 undefined
/home | fetch() | context.env.TEST3 undefined
console.log client Console (toggle route '/about' <> '/')
/home | fetch() | from client
/home | fetch() | process.env.TEST1 undefined
/home | fetch() | context.env.TEST1 undefined
/home | fetch() | process.env.TEST2 TEST2
/home | fetch() | context.env.TEST2 TEST2
/home | fetch() | process.env.TEST3 undefined
/home | fetch() | context.env.TEST3 undefined
I'd expect to have control over environment variables visibility via 'only' option.
E.g. with .env
file
STRIPE_SECRET_KEY="1234"
STRIPE_PUBLISHABLE_KEY="9876"
and configuring ['@nuxtjs/dotenv', { only: ['STRIPE_PUBLISHABLE_KEY'] }]
both variables should be available server-side - while client-side only STRIPE_PUBLISHABLE_KEY
should be accessible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.