I encountered an error while testing my project using vercel dev
. I intended to store environment variables using a .env
file, but I noticed that Vercel interprets content following #
as part of the environment variable. For instance, given MESSAGE=hello world! # a comment
, it parses it as hello world! # a comment
instead of hello world!
. The version of Vercel I’m using is 39.1.2
. I’ve created a simple example that you can access from GitHub - happy-game/vercel-test.
Hello, is it breaking recently or never worked? Could you try following instead?
MESSAGE=hello_world # this is a comment
If your value has <space>
, you need to wrap within quote
then:
MESSAGE="hello world" # this is a comment
This is safest though:
#this is comment
MESSAGE="hello world"
I tried your suggestion, and when I used the
MESSAGE="hello world" # this is a comment
I get
I know that using this will solve the problem nicely
#this is comment
MESSAGE="hello world"
But does this mean that vercel doesn’t allow comments in .env files, but I have no problem parsing this comment file with other tools. For example, in the code I’ve given you, when I run it directly with express, it parses the .env file with dotenv, and that’s fine.
I don’t think it’s Vercel platform issue. As of 13 Aug 2022 7:20 am UTC (Because Node, Angular, javascript etc. keep changing often) this is the status:
You can use #
for comments.
# MY_TEMPORARY_VARIABLE = 'Some value'
But remember, this feature is still in primitive stage as it will not accept comment in same line. Thus:
MY_TEMPORARY_VARIABLE = 'Some value' # This is comment
In this case
let myVar = process.env.MY_TEMPORARY_VARIABLE;
myVar
will hold value:
'Some value # This is comment'
Are you seeing different behavior on local machine if you run npm run build && npm start
or similar?
Thank you for your answer. I searched for some relevant information, but I couldn’t find the standard documentation for .env. However, I did come across the following content in the README of the dotenv project:
To verify this, I tried running the following code and found that Node (at least Node v22.11.0) supports inline comments. It parses the file as I expected:
I uploaded the .env file to Vercel and the parsed results are as follows:
After deploying my test project to Vercel ( my initial question is vercel dev
), I received the following results:
So whether it’s node or the Vercel platform, both support inline comments. However, the vercel dev
environment does not, which leads me to believe that there is indeed an issue with vercel dev
.
Thanks for the feedback! I will report this internally and if we can spot any inconsistency. Unfortunately, I cannot provide an ETA if this can be fixed anytime soon. I will keep you posted as soon as I have more info!
Have a good day!
Just to confirm, you are using latest Vercel CLI, correct?
Yes, the version is 39.1.2.
Alright, thanks! I will keep you posted!
Can you share a minimal reproducible with example .env
file which we can look into? We are unable to reproduce so far.
I have written one, you can cloneit and run npm run dev