When running npm run <script-name>
, the attached command gets executed within the shell linked at /bin/sh
rather than your current shell. A pattern such as:
{src,test}/**/*.js
…is expanded differently in bash, versus zsh, leading to subtle bugs. Instead, defer the glob expansion to the particular tool you’re running, if it has this feature:
{
"scripts": {
// Instead of:
"lint": "eslint {src,test}/**/*.js",
// Write it with quotes:
"lint": "eslint '{src,test}/**/*.js'"
}
}
Here are plain npm alternatives to yarn commands.
# Instead of:
yarn add [--dev] <package>
# Write:
npm install [--save-dev] <package>
# Instead of:
yarn global add <package>
# Write
npm install -g <package>
# Instead of:
yarn publish
# Write:
npm version [major|minor|patch]
npm publish
# Instead of:
yarn <script-name>
# Write:
npm run-script <script-name>
# Or, shorter:
npm run <script-name>
# Instead of:
yarn <bin-name>
# Write:
npx <bin-name>
Use the --no-install
flag prevent npx
from fetching a missing binary from the npm registry.