All I want is to simply use an environment variable in an npm script without installing unnecessary dependencies.
I have a .env
file in the project root, containing
AWS_S3_BUCKET_ID=whatever
My package.json
includes these scripts
"scripts": {
"grep": "echo $(grep AWS_S3_BUCKET_ID .env | cut -d '=' -f2)",
"source": "source .env && echo $AWS_S3_BUCKET_ID",
"test-source": "[ -f .env ] && cat .env && npm run source"
},
Believe it or not, npm run grep
executes, while npm run source
does not.
Now, the absurdity is that npm run source
returns with the following error message
sh: line 0: source: .env: file not found
and npm run test-source
first prints the file content (!!) and then says the file does not exist.
Is there a reason for this behaviour?
edit: I'm on Linux