-
Notifications
You must be signed in to change notification settings - Fork 12k
angular-cli doesn't work when node_modules is located in a parent directory #3864
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
Comments
@wooltar, I appreciate your extensive response, but as I said in the my post I cannot put the |
You could try exporting your node instance's |
@gelliott181 node can find the |
This is the source of that message: Maybe it could be done in a better way that supports your usecase. |
I have a slightly different use case for this same feature, not specific to Docker, and I encounter the same error for the same reason. I have an Angular 2 app living inside an outer npm-based app (the outer app having the package.json). I would like to be able to use the outer node_modules for both apps, without copying anything. Running
In my case I can work around this with a symlink, but that adds complexity and introduces portability concerns. |
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". |
Fixed by #6276. |
This problem appears to still be present in 1.0.4:
In the transcript above, I have these files up a couple of levels in node_modules; node module resolution should find them. Should this issue be reopened? Should I enter a new one instead? |
@kylecordes I think I see what's happening, we added full node resolution to webpack but still check direct dependencies when running |
@filipesilva How about a test case (or N of them) proving the whole thing works with empty local node_modules, and all the deps scattered among 1, 2, 3 levels "up"? Is there an "E2E" part of the test suite where such a thing could fit? |
(Part of such a test could also replace some of the node_module/ZZZ directories with symlinks, to further tease out symlink issues and demonstrate the tooling tolerates symlinks.) |
is there any way to access node_modules outside of angular project,I mean ,instead of accessing relative path can we access absolute path for my development activity. |
Related to #7097 |
@daviddiefenderfer Your solution worked for me (in a .net project), but I do get a side effect on ng build: WARNING in ./ClientApp/node_modules/@angular/compiler/@angular/compiler.es5.js Don't suppose you've any idea's on working around that? |
I have the same issue as @coffeymatt
The warning comes from a sourcemap file which refer to a missing ts file. Didn't found a workaround yet. |
@coffeymatt @draconisNoctis Since this issue is already closed with some code merged, it might be better to start a fresh new issue for the remaining problem, and include an example repository which shows a simple case where there is still a problem. |
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 :) Thanks |
…cli does not support monorepo yet see angular/angular-cli/issues/7097 and angular/angular-cli/issues/3864
Funnily enough, the problem that @maxime1992 is the same one that I have and I also have an identical project structure. Both frontend and backend dependencies being defined in the same package.json file, but as angular-cli belongs in the frontend, it's placed in that sub-directory. |
…cli does not support monorepo yet see angular/angular-cli/issues/7097 and angular/angular-cli/issues/3864
Same problem as @maxime1992 - any solution yet? |
@nickdnk couldn't find anything yet on my side. @filipesilva could you reopen? (should I open a new issue? It really seems to be on this one but wondering...) |
I'm having the same problem aswell. |
You can take a look at nrwl/nx. It should provide an example of what you all need. |
In my case adding
|
I'm using lerna and yarn workspaces in my project. I've used quite a hacky workaround, but it works. Do not recommend this way, but if you do not care; packages/web/bin/install-and-build.sh #!/bin/bash
PREVIOUS_PWD=$PWD
DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd "${DIR}/.."
npm i --ignore-scripts
npm run build
cd $PREVIOUS_PWD
packages/web/package.json {
"scripts": {
...
"prepare": "./bin/install-and-build.sh"
}
...
}
package.json {
"scripts": {
...
// Executes prepare on each package
"prepare": "lerna run prepare"
}
...
}
when running -> Does probably not work on Windows, but should be easy to rewrite |
I recently updated @angular/cli in my project to 6.1.0 and now I am getting the error:
My node_modules is not in the root of my CLI project, but one folder up and symlinked, so node_modules in the CLI project's root points at ../node_modules. Prior to 6.1.0, this worked fine. But 6.1.0 now seems to check if the node_modules directory is inside the CLI project root and this fails on my setup. |
I am getting the same error after upgrading my project to 6.1.0 as @CyberBotX Any news on this please? |
Why would this not just use node's resolution? These checks seem quite artificial. Also... 6.1.0 breaks our setup (same symlinked/docker thing) |
Getting the same error as well after upgrading to 6.1.0. I got my frontend and backend folders, and node_modules is setting in a parent folder. |
+1 ^ Looks like this issue has regressed, please reopen |
For the record, if you would like to continue using The issue is happening only because somehow it's not applying the node module resolution to search in the parent folder if the |
@NightwareSystems that won't work in our case (which is the docker-compose mounted volume problem where we use a symlink inside the image to point node_modules to a folder one level up in the image to prevent them from being shared with the host). I have no idea what features we're missing out on, but we've locked our version of this package to 6.0.8 until the issue is resolved. I go back to my initial question, though, which is why is this not just using node's resolution all the way through? I'm sure there is some reason the devs decided they needed to do explicit checks when running |
@filipesilva ^^^ (at-mentioning you just in case the closed status of this issue has prevented you from seeing the recent comments). This issue has regressed. |
@ryedin can you open a new issue with a reproduction that we can follow to see this problem please? |
@filipesilva Yeah I think I can do that, although will not be able to right away (deadlines and such). Basically though, if you have your node_modules folder sitting in a parent dir and symlinked in, this fails. Hopefully will be able to make a clear repro setup for you later tonight/tomorrow. |
@filipesilva @clydin do you still need a repro setup for this issue? (asking because of @clydin 's response above indicating potential incoming fixes) |
I have a similar issue where I have backend code and an Ionic 4/Angular 6 app in a mono repo with some shared code outside of the angular project
I have node_modules for my angular app in the app itself. If I install all my external deps and build everything is ok. But if I then change my tsconfig.app.json file so it adds a path reference to my shared code, then I get errors resolving 'fs' in aws-sdk (which is pulled in through aws-amplify which I am using) in node_modules. My tsconfig.app.json looks like this
If I remove the |
Why isn't this reopen? This problem persists and as @kylecordes pointed out the current behavior violates the module resolution rules of node.js and breaks every sane MonoRepo structure (like plenty of people here are using). I would like to have my Backend and Frontend dependencies separated and only a small root-node_module. Neither yarn workspaces nor relative PATH inside the package.json is working because suddenly rxjs Objects are not the same anymore (Observable is not assignable to Observable) and angular can't build anymore. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
but running ng --version gives:
Repro steps.
The log given by the failure.
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 dorequire('@angular/core')
the package is correctly loaded.The text was updated successfully, but these errors were encountered: