angular-cli doesn't work when node_modules is located in a parent directory
See original GitHub issuePlease provide us with the following information:
OS?
Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Alpine linux (inside Docker container)
Versions.
Please run
ng --version
. If there’s nothing outputted, please run in a Terminal:node --version
and paste the result here: 1.0.0-beta.24
but running ng --version gives:
Cannot find module '/opt/app/ngapp/node_modules/@angular/common/package.json'
Error: Cannot find module '/opt/app/ngapp/node_modules/@angular/common/package.json'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Class.getVersion (/opt/app/node_modules/angular-cli/commands/version.js:67:25)
at /opt/app/node_modules/angular-cli/commands/version.js:63:67
at Array.forEach (native)
at Class.getDependencyVersions (/opt/app/node_modules/angular-cli/commands/version.js:63:14)
at /opt/app/node_modules/angular-cli/commands/version.js:41:58
at Array.forEach (native)
at Class.run (/opt/app/node_modules/angular-cli/commands/version.js:40:19)
at Class.<anonymous> (/opt/app/node_modules/angular-cli/ember-cli/lib/models/command.js:152:17)
at process._tickCallback (internal/process/next_tick.js:103:7)
Repro steps.
Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.
- ng new ngapp
- cd ngapp
- mv node_modules …
- ng build
The log given by the failure.
Normally this include a stack trace and some more information.
You seem to not be dependending on “@angular/core”. This is an error.
Mention any other details that might be useful.
I want to use angular CLI inside a docker container using docker-compose. I cannot have the node_modules folder inside the source code and a common pattern to solve this issue is to move the node_modules folder to the parent directory. Node will correctly recognise dependencies, but for some reason angular CLI is failing to find the @angular/core
package.
If I run node
and then do require('@angular/core')
the package is correctly loaded.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:26
- Comments:42 (8 by maintainers)
Any news about that?
My use case is the following:
I’m building an app with backend and frontend both merged into a monorepo.
I do have the following structure:
I’d love to hear from you if you’ve managed to solved that in a clean way 😃 (avoiding symlinks or moving .angular-cli.json to top folder)
Thanks
I’ve hit this same problem, the “You seem to not be depending”.
This issue might be more than a “nice to have” - the current behavior breaks the Node module resolution rules:
https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders
I think it can be worked around with some bash hackery to add symlinks - but that’s ugly, and the current behavior violates the Node module resolution “spec”.