Skip to content

Instantly share code, notes, and snippets.

@mchelen
Created May 11, 2018 20:36
Show Gist options
  • Save mchelen/cfd062ee7a8873a97805f52d63f440e5 to your computer and use it in GitHub Desktop.
Save mchelen/cfd062ee7a8873a97805f52d63f440e5 to your computer and use it in GitHub Desktop.
npm run source
➜ npm-script cat package.json
{
"name": "npm-script",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"echo": "source .env && echo $FOO"
},
"author": "",
"license": "ISC"
}
➜ npm-script cat .env
export FOO=bar
➜ npm-script npm run echo
> [email protected] echo /home/mchelen/tmp/npm-script
> source .env && echo $FOO
sh: 1: source: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] echo: `source .env && echo $FOO`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] echo script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mchelen/.npm/_logs/2018-05-11T20_36_32_712Z-debug.log
@tonycassara
Copy link

Hey Mike, I'm having this exact same error. Did you ever figure out how to fix it? Thanks!

@mchelen
Copy link
Author

mchelen commented May 19, 2020

@tonycassara Ah this is an old one, I think mainly my approach was to handle env vars within the application (and not at the script level)using https://www.npmjs.com/package/dotenv
one alternative if you really want to read the env var in the npm script might be https://stackoverflow.com/a/54812256/2043808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment