-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My .env variables just don't work! #7320
Comments
Hi, have you tried using the built-in support for inlining values during build? Here are the docs in case you missed them. |
Thanks, @ijjk! I looked at docs and wondered if it could help me. But I am not gitignoring |
You can still use |
Are you sure, that if I update Nextjs, things won't break? Is it backward-compatible? What do I need to do to upgrade Nextjs? Does updating The code I am using doesn't load the env in production on platforms like Now and Heroku. |
You should be able to upgrade to v8 from v7.0.2 to do so you do To have better compatibility with Now and Heroku I would use So your require('dotenv').config()
const withCSS = require('@zeit/next-css');
const withSass = require('@zeit/next-sass')
const webpack = require('webpack')
module.exports = withSass({
webpack(config) {
config.plugins.push(
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery',
})
)
return config
},
env: {
'MY_SECRET_KEY': process.env.MY_SECRET_KEY
}
}) This will allow you to use |
Sorry for this silly question 😅 But where will |
I tried the way you shown, just doesn't work. Everything broke. 😅 |
vercel/next.js#7320 Everything breaks after making this change to the code.
Did you upgrade Next.js to v8 first? Looking at https://github.com/KumarAbhirup/paprink/blob/development/package.json it is still on v7.0.2. Saying everything broke doesn't really help since that could mean almost anything. Error messages and links to the repo help a lot. |
In the server-side source, For eg,
Things look good on server, but things broke then. It threw these errors in the console 👇
|
Oh yes, you caught it very right, I haven't yet updated |
You are god ❤️ @ijjk, it's working after the update. Just that I need to check if things are working on production or not. Wish me luck.
Everything broke is just my way of expressing that I am sad 😅 Sorry if that sounds rude. 15 yo kid learning here. |
Cool, good luck 👍 I'm gonna close this issue now, if you're still having trouble with this feel free to comment again. |
* ❎ SAVE: Do as stated in the given issue vercel/next.js#7320 Everything breaks after making this change to the code. * 👌 IMPROVE: Update nextjs * 👌 IMPROVE: Specify node version for heroku * 👌 IMPROVE: Install momentjs * ❎ SAVE: Use env in withData
Hi @ijjk, hitting back here again. https://github.com/iqubex-technologies/adify/tree/d5a92640f1b45df3afb6e03125778ef320a84b1d Access the |
I know this is a while afterwards but this should be the accepted solution. I just ran into this same problem but this fixed it with flying colors! Thanks! |
what if you wanna have a different value in .env.development and another in .env.production ? |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
every
.env
variable fails to show up even by usingprocess.env.VARIABLE
clause.To Reproduce
next.config.js
:constants.js
:App.js
Expected behavior
The above example should make env variable work nicely, but just doesn't!
System information
macOS 18.0.0
Chrome Latest
v7.0.2
Additional context
Please help, trying to solve the bug since two days!
The text was updated successfully, but these errors were encountered: