npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm script can't find module without the full path

What I Wanted to Do

I try to run a npm start script. This happens for exemple with create-react-app (but not only!!).
npm start should run react-scripts start

What Happened Instead

Get the following error: sh: react-scripts: command not found
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-app@0.1.0 start: react-scripts start
npm ERR! spawn ENOENT

Changing the script with the full path fixes the issue:
"start": "./node_modules/react-scripts/bin/react-scripts.js start",

Reproduction Steps

npx create-react-app my-app cd my-app npm start


2018-08-12T18_53_47_899Z-debug.log (2.3 KB)

Platform Info

$ npm --versions
{ npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '3',
  nghttp2: '1.32.0',
  node: '8.11.3',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.54',
  zlib: '1.2.11' }

$ node -p process.platform

Can you post the dependencies and devDependencies sections of your toplevel package.json?

Triage note: probably a support issue. It’s very strange if we’re nesting toplevel deps like this. I assume the user assumes we’re hoisting things always?

"dependencies": { "react": "^16.4.2", "react-dom": "^16.4.2", "react-scripts": "1.1.4" },

There are no dev-dependencies in the package.json

Do you have a yarn.lock file inside your my-app directory? I want to make sure create-react-app used npm for this installation.

No yarn.lock, only a package-lock.json. I uninstalled yarn previously to see if this was the issue. Reinstalled node several times too. I even add a new hard-drive and the issue persisted.

The issue disappear with vagrant or any virtual machine…

thanks. I’m not sure why, but I’m unable to reproduce this myself on npm@5.6.0.

What’s the output of npm config get bin-links for you?

it simply returns true

I thought maybe npm relies on some env variables to search the path in the node modules? For some reasons maybe they got messed up on my computer…?

npm run env should answer that question. You can DM the output to me if you don’t want to post it publicly (and I’ll of course treat it as confidential).

How do I send private message here?

I sent you in private the output of npm run env

After DMing with OP, it turns out that this was caused by their project directory existing inside a path that looked like /Users/julien/programming:work/path/to/my-app. This made it so the run-script PATH ended up as PATH="/Users/julien/programming:work/path/to/my/app:$PATH", which made it so the path got split at the :, never actually adding the actual path during the run-script. There is no way to escape this, so the user just renamed their path and things got solved.