Skip to content
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

Yarn PnP Support Status #16980

Open
clydin opened this issue Feb 14, 2020 · 38 comments
Open

Yarn PnP Support Status #16980

clydin opened this issue Feb 14, 2020 · 38 comments

Comments

@clydin
Copy link
Member

@clydin clydin commented Feb 14, 2020

With the release of Yarn 2.0, many users may be interested in trying out the new version of the package manager with the Angular CLI. As of 9.0, the Angular CLI does not natively support Yarn 2.0 and its new package management strategy named Plug’n’Play (PnP). However, native support is currently and actively being investigated with several initial steps already in place. Native support is tentatively scheduled for inclusion in 10.0 or beyond with the goal of integrating new major versions of upstream dependencies that provide native support.

For those that are interested in experimenting with building applications using the new package manager, you can use the following instructions to workaround the current issues.
WARNING: This is not recommended for use with deployed applications and should not be used in a production environment.

  1. Install the workspace dependencies using Yarn 2.0
  2. Install the pnpify package: yarn add -D @yarnpkg/pnpify
  3. Unplug all Angular related packages including third-party libraries used within the application via yarn unplug <package_name>. This should include at a minimum all @angular scoped packages.
  4. If using the E2E command, the webdriver-manager package also needs to be unplugged: yarn unplug webdriver-manager

Once these steps are complete, Angular CLI operations such as serve or build can be used by executing yarn pnpify ng build or yarn pnpify ng serve, respectively.

Please note that manually running the ngcc command with or without the pnpify utility does not currently work.

If any issues are encountered using the workaround steps or for Yarn 2.0 in general, please open a separate issue detailing the problem.

@clydin clydin changed the title Yarn PnP Support Status Yarn 2.0 Support Status Feb 14, 2020
@larixer
Copy link

@larixer larixer commented Feb 15, 2020

Another way of making Angular 9 work with Yarn 2.0 is to use nodeLinker: node-modules in <project_root>/.yarnrc.yml, this will use node_modules scheme for installation.

Yarn team is investing into node_modules support and trying to make it work better than it was in Yarn 1.x, but the future is definitely not with node_modules. node_modules scheme has fundamental technical limitations that makes it not as scalable as Plug'n'Play scheme both in terms of projects size (things become extremely slow on projects with lots of dependencies) and in terms of features we can attach to the scheme (it is hard to keep up with good installation performance even for minimal set of features).

Loading

@ngbot ngbot bot added this to the Backlog milestone Feb 15, 2020
@ngbot ngbot bot added this to the Backlog milestone Feb 15, 2020
@clydin clydin pinned this issue Feb 18, 2020
@andreialecu
Copy link
Contributor

@andreialecu andreialecu commented Feb 25, 2020

Some possibly relevant information regarding improving yarn 2.0 support:

#14841 (comment)

Replacing read-package-tree with a createRequire implementation might be a first step in that direction. The comment above links to a PR in gatsby where they did something similar.

I noticed that @clydin authored most of the code in that file, perhaps #14841 could be fixed in the process as well.

Loading

@Langstra
Copy link

@Langstra Langstra commented Jul 11, 2020

Loading

@klemenoslaj
Copy link

@klemenoslaj klemenoslaj commented Sep 13, 2020

With nodeLinker configured to node_modules I was able to migrate a small Angular CLI project without a single issue, with zero installs configuration even.

Loading

@ronnyek
Copy link

@ronnyek ronnyek commented Oct 6, 2020

I'm not suggesting it would be trivial to fix this and have it automatically work the way yarn 2 works by default out of box, in addition to continuing to support NPM... but I would say this would probably go a long ways to improve developer experience.

Can't wait until node_modules (at least the way it works today) is a thing of the past.

Loading

@andreialecu
Copy link
Contributor

@andreialecu andreialecu commented Oct 6, 2020

There is ongoing work right now in @angular core packages to rework things in a way that would allow Yarn2+PnP to work natively.

You can read more and track the progress here: angular/angular#38099

Loading

@krokofant
Copy link

@krokofant krokofant commented Dec 27, 2020

Since the above linked issue was closed we can track the progress here https://github.com/orgs/angular/projects/2

Loading

@Lonli-Lokli
Copy link

@Lonli-Lokli Lonli-Lokli commented Dec 27, 2020

Is there any specific story for that? A lot of issues getting closed with sentence 'track progress here' but no one issue in this project has specific description from closing ones.

Loading

@napei
Copy link

@napei napei commented Jan 22, 2021

Since the above linked issue was closed we can track the progress here https://github.com/orgs/angular/projects/2

@JoostK I'm interested in when this linker will be available and if it'll solve yarn 2.0 pnp support? The project board appears to be mostly complete, and with 11.1 just coming out I'm wondering if there's a way we can test this before it's released?

Loading

@JoostK
Copy link
Member

@JoostK JoostK commented Jan 22, 2021

Since the above linked issue was closed we can track the progress here https://github.com/orgs/angular/projects/2

@JoostK I'm interested in when this linker will be available and if it'll solve yarn 2.0 pnp support? The project board appears to be mostly complete, and with 11.1 just coming out I'm wondering if there's a way we can test this before it's released?

The linker functionality is indeed functionally working, but we're not yet ready to accept published libraries in this new way (we have yet to review the API that would eventually be published to NPM, which needs special considering as it needs to be backwards/forwards compatible). Regarding pnp support, I suspect that it requires that all dependencies no longer depend on ngcc to work correctly, as otherwise you'd still need ngcc which mutates node_modules. So getting this to a working state is in the hands of library maintainers, once the linker is considered stable.

It may be possible to test this support by manually compiling all dependent libraries using the new way and then seeing if that works, but I suppose that it wouldn't tell the whole story as it wouldn't download packages from NPM, which could arguably affect how pnp works.

Loading

@Lonli-Lokli
Copy link

@Lonli-Lokli Lonli-Lokli commented Feb 6, 2021

Sorry but is my understanding correct, that to make pnp works it's required for all angular libs to get updated by their maintainers?

Loading

@Falven
Copy link

@Falven Falven commented Apr 13, 2021

So does this mean Angular is dead in the water as it will always require management of gigs of dependencies, long CI build times, ngcc compilation, unextendible principles coupled with the insurmountable goal of updating every existing Angular library to support pnp functionality? Or is there a streamlined plan to modernize? It seems like nobody wants to take responsibility for these topics on pnp and everybody is just delegating.

Loading

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented May 20, 2021

Im not sure if the built in angular core and common packages are using the partialIvy format or not however..

The plan is for the Angular packages (framework, CDK, Material, etc) to be published using partial-ivy format from Angular 13.0.0 onwards, to coincide with View Engine removal - assuming that all goes well with this approach during the 12.x active period.

From that point on application developer will begin to be able to benefit setups that require you not to mutate node_modules, such as yarn2, pnpm, lerna, etc, as long as all the Angular libraries in their dependency tree are partial-ivy format. As long as any are still in View Engine format, then you still require ngcc, which will mutate node_modules.

Loading

@wolftrax5
Copy link

@wolftrax5 wolftrax5 commented May 24, 2021

So how to suppose to build a lib? ng build my-lib Cannot find the module to builder, because is on .yarn/cache ,

Loading

@bgotink
Copy link
Contributor

@bgotink bgotink commented May 24, 2021

@wolftrax5 The globally installed @angular/cli doesn't look inside .yarn/cache, you can use yarn ng build my-lib instead.

Loading

@wolftrax5
Copy link

@wolftrax5 wolftrax5 commented May 24, 2021

thanks for the answer @bgotink, I tried, everything run well until the building part.

$ yarn set version berry
$ yarn dlx --package @angular/cli ng new my-workspace --directory=. --packageManager=yarn --create-application=false
$ yarn add ng-packagr@npm:12.0.0
$ yarn ng generate library mpm-lib

$ yarn ng build my-lib
Building Angular Package

------------------------------------------------------------------------------
Building entry point 'my-lib'
------------------------------------------------------------------------------
✖ Compiling TypeScript sources through NGC
ERROR: Cannot locate the 'node_modules' directory.

Need to modify or add something on tsconfig.json? like here but with the ".yarn/cache /"

Loading

@crfrolik
Copy link

@crfrolik crfrolik commented Jun 4, 2021

As long as any are still in View Engine format, then you still require ngcc, which will mutate node_modules.

In that case, would it be possible to get a new a new version of ngcc that doesn't mutate node_modules?

Loading

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jun 4, 2021

As long as any are still in View Engine format, then you still require ngcc, which will mutate node_modules.

In that case, would it be possible to get a new a new version of ngcc that doesn't mutate node_modules?

Indeed we have introduced the new partially compiled Ivy format for Angular libraries.

Loading

@SomebodyOdd
Copy link

@SomebodyOdd SomebodyOdd commented Jul 9, 2021

Indeed we have introduced the new partially compiled Ivy format for Angular libraries.

But how does exactly this help in getting support for Yarn 2.0?
Older third-party packages that do require nggc won't magically go away anytime soon, possibly even never, because there are lots of them out there that just work, even with the latest Angular versions and changes.

If I understand the situation correctly, making all of this work is a matter of storing ngcc's output somewhere other than node_modules, because it's the only thing (in Angular's own tools anyway) that mutate node_modules.
Maybe I'm missing some option that changes the path to ngcc's output? If there is no such feature, are there any plans to make this happen? If not, does that mean that using older packages locks you out of Yarn PnP feature because there is no way to not modify the node_modules directory?

Loading

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jul 26, 2021

The problem ngcc has is that build tools rely upon stuff in node_modules, such as TypeScript typings files (.d.ts files). These tools are not easy to configure to read this information from outside node_modules, and in particular very hard to do this in a way that would work in general.

Since we have a solution (partial compilation and linking) which indeed is designed to avoid the need to mutate node_modules, this is what we would like to move towards going forward.

It is true that packages that do not update to publish in ivy format will lock downstream applications into using ngcc. So I would recommend that the best course of action is to lobby those library projects to migrate to the new format that will enable your application projects to drop ngcc. Angular itself will migrate its own published format to this in 13.0.0, since we will no longer have to support View Engine projects from that version onwards.

Loading

@AwesomeObserver
Copy link

@AwesomeObserver AwesomeObserver commented Jul 28, 2021

Hi! Yarn 3.0 is released, any update for this and 2.0?

Loading

@daniel-brenot
Copy link

@daniel-brenot daniel-brenot commented Aug 16, 2021

So am i given to expect that this should then be somewhat working with the introduction of angular 13.0 later this year?

Loading

@hiepxanh
Copy link

@hiepxanh hiepxanh commented Aug 17, 2021

I switched pnpm 1 year ago since I give up on yarn. I belive it faster than any other and you should give a chance to it

Loading

@mikerentmeister
Copy link

@mikerentmeister mikerentmeister commented Nov 12, 2021

Now that Angular 13 is released, with updates to angular-linker, are there any updates to this?

Loading

@larixer
Copy link

@larixer larixer commented Nov 12, 2021

The title of this issue is misleading, it should rather be Yarn PnP Support Status or Yarn 2+ PnP Support Status, because Yarn 2+ with node_modules (nodeLinker: node-modules in .yarnrc.yml) has been always supported by Angular.

Loading

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Nov 12, 2021

Now that the main Angular packages are published in partial-ivy format, the path to using Yarn PnP is unblocked.
Be aware that as long as your project uses "any" library that is still published in ViewEngine mode, then you will still see ngcc running over your node_modules. In which case you will not be able to use PnP.

Loading

@michaelfaith
Copy link

@michaelfaith michaelfaith commented Nov 12, 2021

I'm excited to have this as an option now!

Loading

@mikerentmeister
Copy link

@mikerentmeister mikerentmeister commented Nov 12, 2021

Now that the main Angular packages are published in partial-ivy format, the path to using Yarn PnP is unblocked.

Any idea why I am still seeing ngcc running when running ng build in an Angular 13 app when ALL dependencies are either set to partial or full ivy compilation?

Loading

@clydin
Copy link
Member Author

@clydin clydin commented Nov 12, 2021

@mikerentmeister If you are encountering an issue with ngcc, please open a separate issue with a reproduction if possible.

Loading

@clydin clydin changed the title Yarn 2.0 Support Status Yarn PnP Support Status Nov 12, 2021
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Nov 12, 2021

So ngcc will run whatever your project setup, since it needs to check for ViewEngine packages. But if there are none there it should effectively be a noop. That being said, I think it may still create a manifest file of all the packages that it checked...

Loading

@larixer
Copy link

@larixer larixer commented Nov 12, 2021

@petebacondarwin

So ngcc will run whatever your project setup, since it needs to check for ViewEngine packages. But if there are none there it should effectively be a noop. That being said, I think it may still create a manifest file of all the packages that it checked...

It might result in an incompatibility with pnp, because pnp mounts zip archives in read-only mode to the require.resolve paths on the virtual file system. If some tool writes straight to <project_root>/node_modules/.dot_something/... it is okay since this path is non-virtual, but writing to the require.resolve paths results in an EROFS error because they are mapped to read-only zip archives.

Loading

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Nov 13, 2021

I believe there is only one problematic place in ngcc regarding "noop" writing to node_modules: writing a "lockfile" during parallel processing:

export function getLockFilePath(fs: PathManipulation) {
  return fs.resolve(require.resolve('@angular/compiler-cli/ngcc'), '../__ngcc_lock_file__');
}

You can see that this is writing to the @angular/compiler-cli/ngcc directory. We should change this to be a top level .ngcc directory directly below the node_modules (or other basePath) directory.

Loading

@kylecordes
Copy link

@kylecordes kylecordes commented Nov 14, 2021

Based on seeing similar issues with other tools in the Node ecosystem, it is broadly safer to write into a node_module/.foo directory, versus inside of a node_modules/FOO/ directory.

Loading

@XsongyangX
Copy link

@XsongyangX XsongyangX commented Nov 14, 2021

I'm looking forward to seeing an improvement to the size of Angular projects! Currently, node modules take up 300+ MB starting from an empty project.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet