New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dceddia opened this Issue Jul 26, 2016 · 20 comments

Comments

Projects
None yet
@dceddia
Contributor

dceddia commented Jul 26, 2016

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.

@dceddia

This comment has been minimized.

Show comment
Hide comment
@dceddia

dceddia Jul 26, 2016

Contributor

Manually running the start.js script works whether I'm using the project copied with cp -a or cp -r:

$ node node_modules/react-scripts/scripts/start.js   # works!

Oddly, when comparing the 2 projects side-by-side, the node_modules directories appear to be identical:

$ create-react-app bug1
$ cp -r bug1 bug2r
$ cp -a bug1 bug2a
$ diff --brief -r bug2a/node_modules bug2r/node_modules  # no output
Contributor

dceddia commented Jul 26, 2016

Manually running the start.js script works whether I'm using the project copied with cp -a or cp -r:

$ node node_modules/react-scripts/scripts/start.js   # works!

Oddly, when comparing the 2 projects side-by-side, the node_modules directories appear to be identical:

$ create-react-app bug1
$ cp -r bug1 bug2r
$ cp -a bug1 bug2a
$ diff --brief -r bug2a/node_modules bug2r/node_modules  # no output
@latentflip

This comment has been minimized.

Show comment
Hide comment
@latentflip

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

latentflip commented 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?

@gaearon

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Jul 26, 2016

Member

I’ll close because this is not actionable for us—it’s just how npm bin works.

Member

gaearon commented Jul 26, 2016

I’ll close because this is not actionable for us—it’s just how npm bin works.

@gaearon gaearon closed this Jul 26, 2016

@cpmech

This comment has been minimized.

Show comment
Hide comment
@cpmech

cpmech Feb 24, 2017

Same problem here

cpmech commented Feb 24, 2017

Same problem here

@kenkoooo

This comment has been minimized.

Show comment
Hide comment
@kenkoooo

kenkoooo 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

kenkoooo commented 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
@fahmidme

This comment has been minimized.

Show comment
Hide comment
@fahmidme

fahmidme Mar 4, 2017

@kenkoooo Thank you so much your solution worked perfectly!

fahmidme commented Mar 4, 2017

@kenkoooo Thank you so much your solution worked perfectly!

@Edxael

This comment has been minimized.

Show comment
Hide comment
@Edxael

Edxael Mar 26, 2017

@kenkoooo Thanks again you solution fix my app.

Edxael commented Mar 26, 2017

@kenkoooo Thanks again you solution fix my app.

@normeno

This comment has been minimized.

Show comment
Hide comment
@normeno

normeno commented Jun 19, 2017

@kenkoooo Thank you!

@allpratik

This comment has been minimized.

Show comment
Hide comment
@allpratik

allpratik Jun 20, 2017

Facing the same issue! But any of above mentioned solutions didn't work for me. I'm on Ubuntu 16.04.

allpratik commented Jun 20, 2017

Facing the same issue! But any of above mentioned solutions didn't work for me. I'm on Ubuntu 16.04.

@dceddia

This comment has been minimized.

Show comment
Hide comment
@dceddia

dceddia Jun 20, 2017

Contributor

If npm is failing it's worth giving yarn a try. I had a few intermittent npm failures on our CI server at one point, and switching to yarn solved them.

Contributor

dceddia commented Jun 20, 2017

If npm is failing it's worth giving yarn a try. I had a few intermittent npm failures on our CI server at one point, and switching to yarn solved them.

@marcusstenbeck

This comment has been minimized.

Show comment
Hide comment
@marcusstenbeck

marcusstenbeck Jun 29, 2017

@allpratik If you have a package-lock.json file, try:

$ rm package-lock.json
$ rm -rf node_modules
$ npm install

marcusstenbeck commented Jun 29, 2017

@allpratik If you have a package-lock.json file, try:

$ rm package-lock.json
$ rm -rf node_modules
$ npm install
@gaearon

This comment has been minimized.

Show comment
Hide comment
@gaearon

gaearon Jun 29, 2017

Member

Also if you use npm 5.x, downgrade to 4.x.

npm -v
npm i -g npm@4.x

npm 5.x has many known issues right now and is buggy.

Member

gaearon commented Jun 29, 2017

Also if you use npm 5.x, downgrade to 4.x.

npm -v
npm i -g npm@4.x

npm 5.x has many known issues right now and is buggy.

@jhaddow

This comment has been minimized.

Show comment
Hide comment
@jhaddow

jhaddow Jul 10, 2017

I upgraded to npm 5.1.0 and it fixed the problem for me. I blew out my node_modules folder after upgrading and ran npm i again.

jhaddow commented Jul 10, 2017

I upgraded to npm 5.1.0 and it fixed the problem for me. I blew out my node_modules folder after upgrading and ran npm i again.

@hajora123

This comment has been minimized.

Show comment
Hide comment
@hajora123

hajora123 Jul 21, 2017

Please help me :(

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@5.3.0
3 info using node@v6.11.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle design-angular2@1.2.0prestart: design-angular2@1.2.0
6 info lifecycle design-angular2@1.2.0
start: design-angular2@1.2.0
7 verbose lifecycle design-angular2@1.2.0start: unsafe-perm in lifecycle true
8 verbose lifecycle design-angular2@1.2.0
start: PATH: C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules.bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules.bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\sts-bundle\sts-3.8.4.RELEASE;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\MongoDB\Server\3.4\bin;C:\Users\hajar\AppData\Roaming\npm;C:\Program Files\nodejs;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules
9 verbose lifecycle design-angular2@1.2.0start: CWD: C:\Users\hajar\Desktop\vsc\veille\app2
10 silly lifecycle design-angular2@1.2.0
start: Args: [ '/d /s /c', 'tsc && concurrently "tsc -w" "lite-server" ' ]
11 silly lifecycle design-angular2@1.2.0start: Returned: code: 2 signal: null
12 info lifecycle design-angular2@1.2.0
start: Failed to exec start script
13 verbose stack Error: design-angular2@1.2.0 start: tsc && concurrently "tsc -w" "lite-server"
13 verbose stack Exit status 2
13 verbose stack at EventEmitter. (C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:289:16)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at EventEmitter.emit (events.js:191:7)
13 verbose stack at ChildProcess. (C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at ChildProcess.emit (events.js:191:7)
13 verbose stack at maybeClose (internal/child_process.js:891:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid design-angular2@1.2.0
15 verbose cwd C:\Users\hajar\Desktop\vsc\veille\app2
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "start"
18 verbose node v6.11.1
19 verbose npm v5.3.0
20 error code ELIFECYCLE
21 error errno 2
22 error design-angular2@1.2.0 start: tsc && concurrently "tsc -w" "lite-server"
22 error Exit status 2
23 error Failed at the design-angular2@1.2.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

hajora123 commented Jul 21, 2017

Please help me :(

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@5.3.0
3 info using node@v6.11.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle design-angular2@1.2.0prestart: design-angular2@1.2.0
6 info lifecycle design-angular2@1.2.0
start: design-angular2@1.2.0
7 verbose lifecycle design-angular2@1.2.0start: unsafe-perm in lifecycle true
8 verbose lifecycle design-angular2@1.2.0
start: PATH: C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules.bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules.bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files\sts-bundle\sts-3.8.4.RELEASE;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.4;C:\Program Files\MongoDB\Server\3.4\bin;C:\Users\hajar\AppData\Roaming\npm;C:\Program Files\nodejs;C:\Users\hajar\Desktop\vsc\veille\app2\node_modules
9 verbose lifecycle design-angular2@1.2.0start: CWD: C:\Users\hajar\Desktop\vsc\veille\app2
10 silly lifecycle design-angular2@1.2.0
start: Args: [ '/d /s /c', 'tsc && concurrently "tsc -w" "lite-server" ' ]
11 silly lifecycle design-angular2@1.2.0start: Returned: code: 2 signal: null
12 info lifecycle design-angular2@1.2.0
start: Failed to exec start script
13 verbose stack Error: design-angular2@1.2.0 start: tsc && concurrently "tsc -w" "lite-server"
13 verbose stack Exit status 2
13 verbose stack at EventEmitter. (C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\lib\utils\lifecycle.js:289:16)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at EventEmitter.emit (events.js:191:7)
13 verbose stack at ChildProcess. (C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\lib\utils\spawn.js:40:14)
13 verbose stack at emitTwo (events.js:106:13)
13 verbose stack at ChildProcess.emit (events.js:191:7)
13 verbose stack at maybeClose (internal/child_process.js:891:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
14 verbose pkgid design-angular2@1.2.0
15 verbose cwd C:\Users\hajar\Desktop\vsc\veille\app2
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\hajar\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "start"
18 verbose node v6.11.1
19 verbose npm v5.3.0
20 error code ELIFECYCLE
21 error errno 2
22 error design-angular2@1.2.0 start: tsc && concurrently "tsc -w" "lite-server"
22 error Exit status 2
23 error Failed at the design-angular2@1.2.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

@felixdivo

This comment has been minimized.

Show comment
Hide comment
@felixdivo

felixdivo Aug 20, 2017

I faced this problem when moving from npm to yarn, and

rm -rf node_modules
yarn install

solved it

felixdivo commented Aug 20, 2017

I faced this problem when moving from npm to yarn, and

rm -rf node_modules
yarn install

solved it

@vjvirtan

This comment has been minimized.

Show comment
Hide comment
@vjvirtan

vjvirtan Oct 24, 2017

If you change node_modules directory you have to change paths also inside node_modules/* package.json files. Search and replace \old_path to new one.
With Eclipse it is easy task with file search and replace.

If you want to change /src path then modify react-scripts/config/paths.js

vjvirtan commented Oct 24, 2017

If you change node_modules directory you have to change paths also inside node_modules/* package.json files. Search and replace \old_path to new one.
With Eclipse it is easy task with file search and replace.

If you want to change /src path then modify react-scripts/config/paths.js

@haoxunba

This comment has been minimized.

Show comment
Hide comment
@haoxunba

haoxunba Nov 16, 2017

thanks,it is save me

haoxunba commented Nov 16, 2017

thanks,it is save me

@Gpia

This comment has been minimized.

Show comment
Hide comment
@Gpia

Gpia Jul 17, 2018

@latentflip You are really right, thank you very much. So many people just said the solution while you told us the truth.

Gpia commented Jul 17, 2018

@latentflip You are really right, thank you very much. So many people just said the solution while you told us the truth.

@techy-manoj

This comment has been minimized.

Show comment
Hide comment
@techy-manoj

techy-manoj Jul 19, 2018

@kenkoooo Thanks it worked for me.

techy-manoj commented Jul 19, 2018

@kenkoooo Thanks it worked for me.

@yzrds

This comment has been minimized.

Show comment
Hide comment
@yzrds

yzrds commented Aug 23, 2018

yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment