-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
nextjs Failed to load env TypeError: Cannot read properties of undefined (reading 'split') #36691
Comments
This seems to be an upstream issue, the current recommendation is to escape the
I noticed this similar thread: #35818 |
@balazsorban44 I'm not sure that this is 100% a duplicate of #37207 . I've encountered the same issue and the problem is that the dollar sign is the last char in the string. Even when you correctly escape it, it still throws the same error. e.g The following will throw the above error
The following will not throw the error
|
The current workaround is based on this comment: motdotla/dotenv-expand#65 (comment) which specifically mentions the escaping of $ character as an ending. I verified this in both a Next.js and non-Next.js reproduction. // index.js
import dotenv from "dotenv"
import dotenvExpand from "dotenv-expand"
const myEnv = dotenv.config()
dotenvExpand.expand(myEnv)
console.log(process.env) # .env
VAR=something$ # throws the error
VAR=something\$ # does not throw the error So since escaping the last $ works, #37207 seems to be caused by the same issue as this. |
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Binaries:
Node: 16.13.1
npm: 7.24.2
Yarn: 1.22.15
pnpm: 6.11.0
Relevant packages:
next: 12.1.7-canary.1
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
Executing on local laptop
Describe the Bug
On starting next with the command npm run dev ("dev": "next") the error message is show:
error - Failed to load env from /Users/path/.env.development.local TypeError: Cannot read properties of undefined (reading 'split')
The simple .env file has
SH_API_BASEURL='http://localhost:3010/api/v1'
NEXT_PUBLIC_SH_API_BASEURL = 'http://localhost:3010/api/v1'
NEXTAUTH_URL=http://localhost:3000
SECRET_COOKIE_PASSWORD=someText
NEXTAUTH_SECRET=AY_PqQ/gmFH6L@:z{szxm.2;~xN:RfD;Rwb`%c/$,/$sometext
JWT_SIGNING_PRIVATE_KEY=&/$someText
If I remove the $ from the keys the .env file will load so the issue is when there is $ in the keys. As this was possible in 12.0.6 it should be possible in the current version.
Expected Behavior
Next 12.0.6 is able to load the .env file without an issue but the current fails to load the .env.
I expect 12.1.16 or 12.1.7-canary.1 to be able to parse the .env file with $ in the value
To Reproduce
To reproduce run npm i next
The text was updated successfully, but these errors were encountered: