Why does node.js install two 'node_modules' folders?

Viewed 1918

Whenever I try to run npm install or npm start I get this error:

bash: line 0: cd: packages/react-scripts: No such file or directory
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aristophanes@1.0.0 start: `cd packages/react-scripts && node bin/react-scripts.js start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aristophanes@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Aristophanes\AppData\Roaming\npm-cache\_logs\2018-11-09T12_14_19_704Z-debug.log

I've no idea why I started getting it. Can anyone shed some light? I've tried uninstall and installing again but it doesn't help. Also, I don't know why but node.js installs 2 node_modules folders in my computer - one in my C://Program Files/nodejs/ directory and another in C://Users/Aristophanes/. The two package.json files in each are different.

Error log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start' ]
2 info using npm@6.4.1
3 info using node@v10.13.0
4 verbose config Skipping project config: C:\Users\Aristophanes/.npmrc. (matches userconfig)
5 verbose run-script [ 'prestart', 'start', 'poststart' ]
6 info lifecycle aristophanes@1.0.0~prestart: aristophanes@1.0.0
7 info lifecycle aristophanes@1.0.0~start: aristophanes@1.0.0
8 verbose lifecycle aristophanes@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle aristophanes@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Aristophanes\node_modules\.bin;C:\Program Files\cmder\bin;C:\Program Files\cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\Program Files\cmder\vendor\conemu-maximus5;C:\Program Files\cmder\vendor\conemu-maximus5\ConEmu;C:\Program Files\nodejs;C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Boxstarter;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Go\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Users\Aristophanes\Go\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\Aristophanes\AppData\Local\Programs\Python\Python37;C:\Users\Aristophanes\AppData\Local\Programs\Python\Python37\Scripts;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\PHP;C:\ProgramData\chocolatey\bin;C:\Program Files\Geth;C:\HashiCorp\Vagrant\bin;C:\Program Files\Git\cmd;C:\composer;C:\Users\Aristophanes\AppData\Roaming\npm;C:\Program Files\nodejs\;C:\Users\Aristophanes\AppData\Roaming\local\bin;C:\Users\Aristophanes\AppData\Local\Microsoft\WindowsApps;C:\Users\Aristophanes\AppData\Local\atom\bin;C:\Users\Aristophanes\AppData\Local\Microsoft\WindowsApps;C:\Users\Aristophanes\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Aristophanes\AppData\Local\GitHubDesktop\bin;C:\Users\Aristophanes\AppData\Roaming\Composer\vendor\bin;C:\Program Files\nodejs\bin;C:\Users\Aristophanes\AppData\Roaming\npm;C:\Program Files\Git\mingw64;C:\Program Files\Git\usr\bin;C:\Program Files\cmder
10 verbose lifecycle aristophanes@1.0.0~start: CWD: C:\Users\Aristophanes
11 silly lifecycle aristophanes@1.0.0~start: Args: [ '-c',
11 silly lifecycle   'cd packages/react-scripts && node bin/react-scripts.js start' ]
12 silly lifecycle aristophanes@1.0.0~start: Returned: code: 1  signal: null
13 info lifecycle aristophanes@1.0.0~start: Failed to exec start script
14 verbose stack Error: aristophanes@1.0.0 start: `cd packages/react-scripts && node bin/react-scripts.js start`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
14 verbose stack     at EventEmitter.emit (events.js:182:13)
14 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
14 verbose stack     at ChildProcess.emit (events.js:182:13)
14 verbose stack     at maybeClose (internal/child_process.js:962:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
15 verbose pkgid aristophanes@1.0.0
16 verbose cwd C:\Users\Aristophanes
17 verbose Windows_NT 10.0.17134
18 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
19 verbose node v10.13.0
20 verbose npm  v6.4.1
21 error code ELIFECYCLE
22 error errno 1
23 error aristophanes@1.0.0 start: `cd packages/react-scripts && node bin/react-scripts.js start`
23 error Exit status 1
24 error Failed at the aristophanes@1.0.0 start script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]
3 Answers

The one in C://Program Files/nodejs is the global packages that you are installing.

The one in the project are the dependencies for the project.

And this problem is probably ocurring because you are running npm install on a folder without a package.json.

I think you are having this challenge because you are not in your project folder navigate into your project folder then do your installation .just cd then the name of your app and press the enter key // like this:

PS C:\Users\Alice\Desktop\project-folder> cd react-app

I haven't sourced any explainer as to why the two node_modules. Noticing that the one in ./Program Files/nodejs are default pkgs while those in my Users dir are 3rd party added via npm. Noticing also in the latter the presence of package-lock.json which will lock the version while the former contains only package.json.

Related