question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm start fails after copying a generated project to a new directory

See original GitHub issue

Here is the failure:

$ npm start

> bug-test@0.0.1 start /Users/dceddia/Projects/pure-react/sandbox/bug-test-copy
> react-scripts start

module.js:339
    throw err;
    ^

Error: Cannot find module 'cross-spawn'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/dceddia/Projects/pure-react/sandbox/bug-test-copy/node_modules/.bin/react-scripts:3:13)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:457:10)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/5.0.0/bin/node" "/Users/dceddia/.node/bin/npm" "start"
npm ERR! node v5.0.0
npm ERR! npm  v3.3.12
npm ERR! code ELIFECYCLE
npm ERR! bug-test@0.0.1 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bug-test@0.0.1 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bug-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts start
npm ERR! You can get their info via:
npm ERR!     npm owner ls bug-test
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dceddia/Projects/pure-react/sandbox/bug-test-copy/npm-debug.log

To reproduce:

$ create-react-app bug-test
$ cp -r bug-test bug-test-copy
$ cd bug-test-copy
$ npm start

At first I thought it might have something to do with having run npm start from within bug-test before copying it, but skipping that step didn’t have any effect.

Removing node_modules and reinstalling them fixes it:

$ cd bug-test-copy
$ rm -r node_modules
$ npm install
$ npm start   # works!

Using cp -a instead of cp -r does not cause the problem:

$ create-react-app bug-test
$ cp -a bug-test bug-test-copy
$ cd bug-test-copy
$ npm start   # works!

I’m running Node 5.0.0 and npm 3.3.12.

I tried (via nvm) with Node 6.3.1 and npm 3.10.3 and got the same behavior.

The cp -a vs cp -r makes me think this might be an npm bug.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

155reactions
kenkoooocommented, Mar 3, 2017
$ npm install -g npm@latest  # or, npm install -g npm@latest --prefix "C:\Program Files\nodejs"
$ rm -rf node_modules        # or, `cmd /c rmdir /s /q node_modules` on Windows
$ npm install
34reactions
latentflipcommented, Jul 26, 2016

I was intrigued so I dug into this real quick.

The problem is that cp -r doesn’t necessarily preserve symlinks, and just copies the file contents instead.

npm run start uses the react-scripts bin file, which is at ./node_modules/.bin/react-scripts however, this should be symlinked into ./node_modules/react-scripts/bin/react-scripts.js. This symlink means that npm can find the cross-spawn module which is a subdependency of react-scripts.

However, cp -r doesn’t preserve that symlink, and instead just copies the contents of the .bin file. npm now doesn’t know to look within the node_modules/react-scripts/node_modules dir to find cross-spawn.

cp -a will preserve symlinks, so avoids the problem.

Looks like diff in general just resolves symlinks and compares the file contents, hence it not spotting this issue.

I’m not sure that this can really be resolved by create-react-app. Perhaps npm should be detecting non-symlinks in ./node_modules/.bin I dunno?

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm start fails after copying a project to a new directory
hi i move my project to a new directory and now i can't compile each time i npm start I get this error...
Read more >
npm-ci
An easy way to do this is to run, for example, npm config set legacy-peer-deps=true --location=project and commit the .npmrc file to your...
Read more >
Deployment
Sometimes npm run build works locally but fails during deploy via Heroku. Following are the most common cases. "Module not found: Error: Cannot ......
Read more >
Build a Node.js and React app with npm
Fork and clone the sample repository; Create your Pipeline project in Jenkins ... If you've already run though another tutorial, you can skip...
Read more >
Configure Node.js apps - Azure App Service
Configure a Node.js app for Azure App Service · As described in npm docs, scripts named prebuild and postbuild run before and after...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found