npm-run-all icon indicating copy to clipboard operation
npm-run-all copied to clipboard

Getting "Error: Cannot find module" when running basic setup

Open kennyjwilli opened this issue 2 years ago • 2 comments

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

  1. npm install
  2. Run npx npm-run-all echo.
  3. Receive the above error.

Oddly, if I just run npm run echo, I get the expected output.

npm run echo

> echo
> echo foo

foo

kennyjwilli avatar Nov 19 '21 16:11 kennyjwilli

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 .

gera2ld avatar Nov 28 '21 16:11 gera2ld

Switching back to npm 6 is a workaround. But obviously not great.

mrclay avatar Feb 20 '23 20:02 mrclay