mysticatea / npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
MIT License
5.72k stars 240 forks source link

Running a script through "npm-run-all" affects the resolution behavior #177

Closed slavafomin closed 5 years ago

slavafomin commented 5 years ago

Hello!

Thank you for this great tool!

However, we've stumbled upon a strange behavior, maybe you could clarify it for us.

I've created a very simple script with the following content:

console.log(require.resolve('node-sass'));

When I execute it directly via npm run, it says that it can't find a package, which is correct, because the package is not installed locally in the project. But, when I run the same script using npx run-s, the package gets resolved somehow to a path, which shouldn't be available to the local project.

How does the "npm-run-all" affects a resolution behavior?

Also, our project is maintained with Rush.

Thanks!

TehShrike commented 5 years ago

Is npm-run-all installed globally, or locally, or both? Is it listed as a dependency in the local package.json file?

mysticatea commented 5 years ago

What does it happen if you use ./node_modules/.bin/run-s?

slavafomin commented 5 years ago

Is npm-run-all installed globally, or locally, or both? Is it listed as a dependency in the local package.json file?

The npm-run-all is installed locally as a dev-dependency in my package.json. There is no global version installed:

  "devDependencies": {
    …
    "npm-run-all": "^4.1.5",
    …
  }

What does it happen if you use ./node_modules/.bin/run-s?

The result is the same as with npx run-s, e.g. the dependency is resolved.

slavafomin commented 5 years ago

Wow, it looks like the mystery is solved. It appears that Rush replaces the script in ./node_modules/.bin directory with it's own bash-script that sets the NODE_PATH variable, which actually changes the resolution behavior.

It seems that this issue is not related to the npm-run-all itself. Sorry for the false alarm.