npm-run-all
npm-run-all copied to clipboard
Getting "Error: Cannot find module" when running basic setup
I am receiving the following error after setting up a basic setup with npm-run-all.
npx npm-run-all echo
Watching /private/tmp/npm-test and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./node_modules ; is listed in .gitignore
Starting: echo
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/private/tmp/npm-test/echo'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Environment
- node: v16.13.0
- npm: 8.1.0
- npx: 8.1.0
- MacOS 12.0.1, M1 processor
package.json
{
"name": "test",
"devDependencies": {
"npm-run-all": "4.1.5"
},
"scripts": {
"echo": "echo foo"
}
}
Steps to reproduce
-
npm install
- Run
npx npm-run-all echo
. - Receive the above error.
Oddly, if I just run npm run echo
, I get the expected output.
npm run echo
> echo
> echo foo
foo
Just encountered the same issue. Looks like npm-run-all
does not work with npx
because it always regards process.env.npm_execpath
as package manager, which is wrong when npx
is used.
npm-run-all command
actually runs $npm_execpath run command
, when $npm_execpath
is npm
or yarn
, everything goes well.
But in the case of this issue $npm_execpath
becomes npx
, so it runs npx run echo
and fails. It took me a while to find out why npx
kept trying to install run
.
There is already a detailed analysis in #209 .
Switching back to npm 6 is a workaround. But obviously not great.