next.js
next.js copied to clipboard
process.env variables are undefined at frontend
Verify canary release
- [X] I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 Binaries: Node: 18.11.0 npm: 8.19.2 Yarn: N/A pnpm: N/A Relevant packages: next: 13.0.3-canary.1 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
What browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
next export
Describe the Bug
env variables are undefined in the frontend tho I used PUBLIC_NEXT prefix.
question: Can I also use env variables in next export?
Expected Behavior
env variables are not undefined in frontend
Link to reproduction
https://github.com/nitz-iron/next-env-var-undef
To Reproduce
- npm start
- enter to "/" path
- in chrome console: process.env is an empty object / process.env.NEXT_PUBLIC_GANAV = undefined
I cloned your repo, created an environment variable in .env.local called NEXT_PUBLIC_GANAV=Hello
and it works. Could there be a mistake in your .env.local file.
![Screenshot 2022-11-08 at 12 18 07 PM](https://user-images.githubusercontent.com/11394862/200632173-c39a9839-2d95-4c62-a706-255f55b30cc4.png)
You're right (I am the author from different user). I see it works if I omit the && from the npm start command. But what about next export? how can I do it there via npm command?
I succeeded to do it like this:
tomorrow I'll check if it works on next served via custom express server, pls do not close.