Pass through scripts can modify paths

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.

Last Updated: 2022-05-26

Pass-through scripts can modify paths:

My package.json had a scripts key containing:

{
  "test": "jest"
}

As expected, it could be executed with:

$ npm test

Yet running $ jest on the command line failed. How is that possible?

The reason is that the npm command first searches inside node_modules/.bin/ for commands, i.e. adding it to $PATH. This folder contains the jest program. However the $PATH for my terminal did search this folder.

Lessons

Scripts can modify path