-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Angular CLI and monorepos (like lerna, yarn workspaces) #7097
Comments
At this point, this is me primarily asking: "How is Angular CLI meant to work with monorepos?" It the answer is "please use Angular CLI from the monorepo root directory", I can live by that. |
I'm not really familiar with the Yarn workspaces, but the CLI currently attributes meaning to the location both both It expects them to be in the same dir, assumes that dir is the project root, and that there's also a So no, I don't think the CLI is currently well equipped to work in monorepos. But that's not because we don't want it to, just because it wasn't ever much of a concern. If there's a reasonable way of making it work I'm all for it really. I think some of the CLI users are using it with Lerna, but I don't know the details of it. The important bits of monorepo support is that it's not really specific to any single setup (like Lerna or these Yarn workspaces), and that it doesn't compromise the current setup. |
Regarding my original post: I need to check whether Regarding discussion: What may happen in monorepos (at least in yarn workspaces) that they install "(workspace-)local" and "(project-)global" dependencies. Example:
Let aside potential version conflicts (which are in the hand of the user). The difficulty for the webpack build would be to resolve modules "by walking up the tree until it finds one". I remember from past custom webpack configs that you had to pass the location of the Is this even possible to resolve modules from different directories? |
I think it's possible, yeah. But now that got me thinking how that happens with peer deps. In your example there's different versions of packages that really want the same version of the peer deps. So through node module resolution you'd end up getting the different versions. But even though the module resolution might work, I think you'd get.... a static analysis error. Which is what you actually got initially:
This wasn't just an error finding a module, it was an error finding a module while using static analysis to find lazy loaded modules (we do that on every build, not just AOT). So I ask... what happens in your setup when you install all the And if that works the only thing we need to do to support it is to relax the See where it tries to use path join with the project root? We should be able to use node module resolution instead like https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/utilities/require-project-module.ts. |
@filipesilva Ack.
$ ng build
WARNING in ../~/@angular/compiler/@angular/compiler.es5.js
(Emitted value instead of an instance of Error) Cannot find source file 'compiler.es5.ts': Error: Can't resolve './compiler.es5.ts' in '/Users/David/Projects/github/spektrakel-blog/a-glimpse-at-yarn-workspaces/node_modules/@angular/compiler/@angular'
@ ../~/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic.es5.js 7:0-72
@ ./src/main.ts
@ multi ./src/main.ts So still the same error. $ ng build --preserve-symlinks
Your global Angular CLI version (1.3.0-rc.3) is greater than your local
version (1.3.0-beta.0). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
Hash: d97b10ba4761c0902221
Time: 19229ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.js.map (main) 94.3 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 1.8 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered] So with Also AoT / Prod build! $ ng build --preserve-symlinks --aot --prod
Your global Angular CLI version (1.3.0-rc.3) is greater than your local
version (1.3.0-beta.0). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
Hash: 31d53744fb697d9b9f87
Time: 19407ms
chunk {0} polyfills.3b4be225e7f6a233ebb3.bundle.js (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.a772681d78c70ca6637d.bundle.js (main) 101 kB {3} [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk {3} vendor.e839d82f8b5326dc3f41.bundle.js (vendor) 761 kB [initial] [rendered]
chunk {4} inline.6eaed4d70fc63a0f7481.bundle.js (inline) 0 bytes [entry] [rendered] |
Ok, so this is progress. I take it the whole partial dep thing still won't work too well (for peer deps at least) but at least stuff seems to work if we tell webpack to pretend symlinks aren't really there. BTW |
This was merged recently in TS and is probably available in nightly so I think the symlinks won't be required anymore: microsoft/TypeScript#16274 Edit: this doesn't solve what I thought it would :( |
Similar to feature request #6083 |
If you want to make some tests without having to worry about all that, a really simple monorepo for backend/frontend like the following, does not work:
(then running from root folder |
…cli does not support monorepo yet see angular/angular-cli/issues/7097 and angular/angular-cli/issues/3864
just fyi, for packages that do not support the module hoisting done in yarn workspaces there is now a |
…cli does not support monorepo yet see angular/angular-cli/issues/7097 and angular/angular-cli/issues/3864
Not quite sure if this is related, but I get the following error:
I use lerna with yarn workspaces. I currently have the
Anyone found a workaround yet? |
working root package.json
|
I'm subscribing here, trying to use Yarn workspaces. |
Hello, I'm working with angular 7.2.x and I think that problem was fixed on this version, as I see here : #11685 But I still can not get it to work, and I would like to avoid using nohoist. If someone is able to say me what isn't right, or if I still need to use nohoist, that would be very helpfull :) |
I had a similar issue. |
I'm having an issue I think related to this one. I'm trying Ivy, in a lerna workspace. With Date: 2019-06-13T21:52:59.215Z
Hash: 55c7e38a65bd19305a57
Time: 9864ms
chunk {0} runtime-es5.9c308a63d02029c20228.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main-es5.4af9b61479361f268d39.js (main) 128 bytes [initial] [rendered]
chunk {2} polyfills-es5.76fb5c306a2dd7f67a99.js (polyfills) 68.1 kB [initial] [rendered]
chunk {3} styles.691cb89d8238aaa5586f.css (styles) 63.4 kB [initial] [rendered]
ERROR in ../../node_modules/@angular/material/toolbar/typings/toolbar-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of AppMaterialModule, but could not be
resolved to an NgModule class
../../node_modules/@angular/material/toolbar/typings/toolbar-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of AppMaterialModule, but could not be resolved
to an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/button/typings/button-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be resolved to an NgModule class
../../node_modules/@angular/material/card/typings/card-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be resolved to
an NgModule class
../../node_modules/@angular/material/form-field/typings/form-field-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be
resolved to an NgModule class
../../node_modules/@angular/material/input/typings/input-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be resolved to an NgModule class
../../node_modules/@angular/material/select/typings/select-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be resolved to an NgModule class
../../node_modules/@angular/material/tabs/typings/tabs-module.d.ts(8,22): error TS-996002: Appears in the NgModule.imports of SharedMaterialModule, but could not be resolved to
an NgModule class
../../node_modules/@angular/material/button/typings/button-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/card/typings/card-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be resolved to
an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/form-field/typings/form-field-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be
resolved to an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/input/typings/input-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/select/typings/select-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class
../../node_modules/@angular/material/tabs/typings/tabs-module.d.ts(8,22): error TS-996003: Appears in the NgModule.exports of SharedMaterialModule, but could not be resolved to
an NgModule, Component, Directive, or Pipe class
src/app/shared/shared-material.module.ts(24,14): error TS-996002: Appears in the NgModule.imports of SharedModule, but itself has errors
src/app/shared/shared-material.module.ts(24,14): error TS-996003: Appears in the NgModule.exports of SharedModule, but itself has errors
src/app/shared/shared.module.ts(13,14): error TS-996002: Appears in the NgModule.imports of AuthModule, but itself has errors
src/app/app-material.module.ts(10,14): error TS-996002: Appears in the NgModule.imports of AppModule, but itself has errors I ran |
So in packages, I got an error: This is because @angular doesn't exist in the root node_modules Any ideas how to solve this problem? please @filipesilva angular is v9, and still doesn't support lerna/yarn? :( |
I think there have been recent updates to Angular because I'm using Ivy with no problems in a yarn workspace. The only remaining issue for me was that |
@andreialecu Do your changes enable |
@diminutivesloop as far as I remember, yes. That was the main reason behind opening that PR. |
Angular now has direct support for monorepos, so that should fulfill this use case: https://angular.io/guide/file-structure#multiple-projects. We don't directly support Yarn / Lerna workspaces, but Angular's built-in support with the CLI should satisfy the same use cases. If there are significant feature gaps that require Yarn / Lerna, then please file a separate issue about it and we can try to support those use cases directly. |
The most significant gap IMO is the ability to run multiple projects with one command, in the right order (dependencies) and in parallel if possible. A while back I wrote a CLI that did exactly that on top of Angular CLI as an exercise, so I am pretty sure it should be doable. However, that request already exists: #11002 |
Can't you already achieve that with nrwl/nx? It comes with a myriad of commands for testing/linting/building only things that were affected, running things in parallel, looking at dep graphs etc |
Yes of course, the thread I linked acknowledged nrwl as well I think. But the question was about a significant feature missing in Angular CLI but is supported in other monorepo environments, so I think my point stands.
If Angular CLI built-in support claims to satisfy the same use cases, I think a simple command to build a library with its dependencies should be maybe supported? 🤔 NX is good of course, but again if someone would like to use Angular as plain as it gets, I think this feature could be quite beneficial. |
We're aware that having to |
@dgp1130 I'd be more than willing to help in this if help is needed. I can as well publish my private CLI for inspiration. That CLI basically reads the source code and builds the dependency tree and then from that can execute the libraries the the proper order. As well I added the feature to run the builds in parallel when possible. Expand to see the examplesparallel-builds.movverbose-parallel-builds.movinteractive.mov |
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. |
Bug Report or Feature Request (mark with an
x
)Versions.
This in itself manifests the error.
Repro steps.
A full repro can be found at GitHub repo spektrakel-blog/a-glimpse-at-yarn-workspaces
Initially, faced the "You seem to not be depending on @angular/core" error.
This goes down to a sanity check whether Angular is installed as a local dependency.
However, there are more errors with yarn workspaces, when dependencies from a workspace (or "sub-project", or "sub-package") are installed to the top-most
node_modules
directory of the workspaces root.Then, it ends up w/ file structure:
Workspace root
package.json
:Demo workspace
package.json
:Now, dependencies are installed to
node_modules
and not todemo/node_modules
:Then, running
ng build
from thedemo
folder errors:As a workaround, it's possible to symlink "@angular/core":
But then we only get one error further until:
Which suggests that Angular CLI isn't really meant to work w/ "sub-projects" like yarn worksapces.
The log given by the failure.
See above.
Desired functionality.
Angular CLI and webpack should resolve depndencies from "top-level"
node_modules
.The sanity check should honor node's module resolution algorithm (looking up recursively up the file tree).
Mention any other details that might be useful.
Related to #6504
A related change was implemented in #6475 (resolve in all available node_modules), but it seems that it does not address this use case.
The text was updated successfully, but these errors were encountered: