Skip to content
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

TypeError: Cannot read property 'split' of undefined #65

Closed
moselhy opened this issue Feb 27, 2022 · 6 comments
Closed

TypeError: Cannot read property 'split' of undefined #65

moselhy opened this issue Feb 27, 2022 · 6 comments

Comments

@moselhy
Copy link

moselhy commented Feb 27, 2022

A simple .env file containing:

SERVER_HOST=localhost:8080
CORS_ALLOWED_ORIGINS=/${SERVER_HOST}(:[0-9]+)?$/

will throw this error when configured:
TypeError: Cannot read property 'split' of undefined

This issue wasn't happening in version 5.1.0 but I noticed it in 8.0.1

moselhy added a commit to moselhy/dotenv-expand that referenced this issue Feb 27, 2022
@motdotla
Copy link
Owner

You just need to escape the ending $ sign:

SERVER_HOST=localhost:8080
CORS_ALLOWED_ORIGINS=/${SERVER_HOST}(:[0-9]+)?\$/

Otherwise dotenv-expand attempts to interpolate it.

You raise a good issue though that ideally it should be smart enough to recognize a dollar sign followed by some text as a variable, and dollar signs on their own could exist on their own without being escaped. This would need to be modified in the regex.

I'll look into that, but for now you can just modify your .env file.

@MattIPv4
Copy link

👋 Just wanted to +1 this as we've also just run into this after updating Next.js, which bumped from 5.x to 8.x for this lib and introduced this bug.

@felipeespitalher
Copy link

felipeespitalher commented Sep 8, 2022

I'm using serverless-dotenv-plugin and few of my env vars have "$".

I solved escaping all $

Ex:

KEY=VAL\\$UE

@DollarAkshay
Copy link

Had to change some of my passwords that had $ in them because of this. LOL

@gabriel-hahn
Copy link

In version 10.0.0, having a $ is no longer a problem, but it seems that having $$ in .env values can break it again. I just ran into this when upgrading NextJS: @next/env upgrade, which also upgraded this package from version 5.1.0 to 10.0.0.

Example:
TOKEN ="abcd$1234" good 👍🏼
TOKEN ="abcd$$1234" bad 👎🏼

@motdotla
Copy link
Owner

in v11.0.0 functionality will be this:

  • TOKEN ="abcd$1234" -> abcd
  • TOKEN ="abcd$$1234" -> abcd$

if you need to include the $ sign escape it. we are considering supporting single quotes as an alternative (so you would not need to escape the dollar sign)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants