Today at work I found out that the following script from the
package.json was not working on my colleague's machine. He is running
Ubuntu. I have seen this happening also on the Arch distribution.
"start:dev": "source .env; nodemon index.js"
This script aims at sourcing a bunch of environement variables and then only running the application.
This had worked under OSX since the beginning of the project though.
What is happening
Basically, if not specified as a
npm-run uses the system's
/bin/sh as shell to execute commands in script entries.
This means that if your system is using a default shell that does not implement the
source command, you are getting this
source: not found error.
npm gets you covered 😅
The solution is to specify the
script-shell config, before running the
The script entry presented in the context section above would become:
"start:dev": "npm config set script-shell \"/bin/bash\"; source .env; nodemon index.js"
It is a bit wordy but does usually get you out of trouble as long as the system
running the command implements