npm script can't find module without the full path

cli

(Julien Demarque) #1

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! code ELIFECYCLE
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

Details

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
darwin

(Kat Marchán) #2

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


(Julien Demarque) #4

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


(Julien Demarque) #5

There are no dev-dependencies in the package.json


(Kat Marchán) #6

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.


(Julien Demarque) #7

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.


(Julien Demarque) #8

The issue disappear with vagrant or any virtual machine…


(Kat Marchán) #9

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?


(Julien Demarque) #10

it simply returns true


(Julien Demarque) #11

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…?


(Kat Marchán) #12

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).


(Julien Demarque) #13

How do I send private message here?


(Julien Demarque) #14

I sent you in private the output of npm run env


(Kat Marchán) #15

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.


(Kat Marchán) #16

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.