Solvedangular cli Dependency resolution is broken with 'yarn --pnp' (Yarn Plug 'n' Play)

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc


ng: 6.0.0
yarn: 1.12.0 (RC)
node: v8.11.3
os: OSX 10.13.6

Repro steps

  1. Install yarn RC 1.12.0
  2. clone
  3. go in the cloned repo
  4. run yarn --pnp (switches it to pnp mode)
  5. run yarn build

The log given by the failure

Could not find module "@angular-devkit/build-angular" from "/Users/ssieber/dev/ng-yarn-pnp".
Error: Could not find module "@angular-devkit/build-angular" from "/Users/ssieber/dev/ng-yarn-pnp".
    at Object.resolve (/Users/ssieber/Library/Caches/Yarn/v3/npm-@angular-devkit-core-0.6.8-3b09d97bd2588f0091df11921f7ed772431806aa/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/Users/ssieber/Library/Caches/Yarn/v3/npm-@angular-devkit-architect-0.6.8-977acc605aba45d21b95ca704cc99492e14299dd/node_modules/@angular-devkit/architect/src/architect.js:132:40)
    at Observable._trySubscribe (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/Observable.js:44:25)
    at Observable.subscribe (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/Observable.js:30:22)
    at (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/operators/tap.js:32:23)
    at Observable.subscribe (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/Observable.js:25:22)
    at /Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/util/subscribeTo.js:22:31
    at Object.subscribeToResult (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/util/subscribeToResult.js:10:45)
    at MergeMapSubscriber._innerSub (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/operators/mergeMap.js:82:29)
    at MergeMapSubscriber._tryNext (/Users/ssieber/Library/Caches/Yarn/v3/npm-rxjs-6.3.3-3c6a7fa420e844a81390fb1158a9ec614f4bad55/node_modules/rxjs/internal/operators/mergeMap.js:76:14)

Desired functionality

I'd like it work ;) - Specifically when I'm not using yarn pnp, I get this:

yarn run v1.12.0
warning ../package.json: No license field
$ ng build
Date: 2018-10-03T18:44:42.889Z
Hash: df3a0ea990e4eeeb9455
Time: 8768ms
chunk {main} main.js, (main) 25.6 kB [initial] [rendered]
chunk {polyfills} polyfills.js, (polyfills) 227 kB [initial] [rendered]
chunk {runtime} runtime.js, (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, (styles) 15.6 kB [initial] [rendered]
chunk {vendor} vendor.js, (vendor) 3.54 MB [initial] [rendered]
✨  Done in 12.48s.

Mention any other details that might be useful

This is apparently caused the build tool implementing it's own dependency resolution. Yarn pnp provides an alternative dependency resolution that eschews node_modules. It's an experimental feature. I've filed an issue in their repo, but they directed me here, since you guys seem to be using custom resolution. See yarnpkg/yarn#6482

14 Answers

βœ”οΈAccepted Answer

Let me know if someone with Angular knowledge is interested to make a peer programming session to make the needed changes. I'd be happy to help πŸ™‚

Other Answers:

As mentioned, Angular seems to do the resolution by itself, which causes issues when operating within exotic installation schemes where some assumptions don't necessarily hold. Fixes look quite easy though!

I've made a few quick fixes to see what's the minimal amount of changes needed to make it work, and listed them below. Let me know what you think, and if you want to setup a call to discuss all this in more details I'm all for it! Please ping me by email or Twitter or this thread πŸ™‚

Missing dependencies

Plug'n'Play detected various unsafe behaviors that probably should be fixed whatever you choose to do:

  • @angular/cli omits to list the tslib dependency in its package.json
  • @angular/compiler-cli also omits tslib
  • @angular-devkit/build-angular omits loader-utils and semver
  • webpack-subresource-integrity relies on a hack (opened waysact/webpack-subresource-integrity#90)


Cannot locate node_modules

Hmm, can I skip this one? That's kinda expected, I'd say πŸ˜›

Overall there's a bunch of node_modules assumptions there, so I guess it would make more sense for you to give it a look yourself - from what I gather it wouldn't be too much work to have something more generic. The cache folder can be set to .pnp/pkgdata/angular when you're in a PnP environment (instead of node_modules/something, which is risky), and the Webpack loaders can be easily (really!) loaded through the use of the pnp-webpack-plugin package. It's really just two extra lines in your configuration.


Basically just have to add a guard to directly use the PnP API when operating under a PnP environment (I can see the reticence to special case, but keep in mind this API is precisely meant to offer a common abstraction to how various projects could decide to layout the dependencies - in this sense it's more generic than resolve, which only supports node_modules).

function resolveProjectModule(root, moduleName) {
    if (process.versions.pnp) {
        return require('pnpapi').resolveRequest(moduleName, `${root}/`);
    } else {
        return resolve.sync(moduleName, { basedir: root });

Note that this has to be done in @angular-devkit/build-angular as well (but I supposed the source code is mutualized between those two locations?).


Similarly to the previous note, a small edit is needed:

function resolve(x, options) {
    // ...
    const extensions = options.extensions || Object.keys(require.extensions);
    const basePath = options.basedir;
    if (process.versions.pnp) {
        const orig = x;
        const pnpapi = require('pnpapi');
        try {
            if (options.resolvePackageJson)
                x += `/package.json`;
            x = pnpapi.resolveRequest(x, `${basePath}/`, {extensions});
        } catch (error) {
            x = orig;
    // ...

Update on Yarn 2: the first release candidate is available

The lead Yarn maintainer @arcanis seems eager to assist, so it'd be awesome if an Angular dev could find some time to work with him on this πŸ˜€

@laurencefass Further Yarn development happen mostly on the v2 trunk πŸ™‚

I'm happy to report that thanks to @Embraser01 and @larixer we're very close from a fully working Angular! I was actually about to merge our first Angular E2E test to track potential regressions.

While everyone can use whatever tool they feel appropriate, it is also important to note that Angular is supported by Yarn 2

  1. For PnP install strategy via @yarnpkg/pnpify tool.
  2. Yarn 2 also supports node_modules install strategy via nodeLinker: node-modules option.
    For details please check this pinned issue on Angular CLI:

Related Issues:

angular cli Issue: Cannot read property 'thisCompilation' of undefined
Here is the answer from issues #9793 : npm remove webpack npm install webpack@3.11.0 ...
angular cli Error | Could not find plugin "proposal-numeric-separator" | Generating ES5 bundles for differential loading
Try to install @babel/compat-data: ~7.8.0 to devDependencies This is the only workaround which helpe...
angular cli Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")
Probably not the same cause but we had the same error (Cannot read property 'length' of undefined) w...
angular cli ng serve method ip not open in another machines
The solution is simple Just bind to the correct interface address via ng serve --host= ...
angular cli Incorrect JS paths when ng build -prod is deployed in a subfolder
When you're deploying to non-root path within a domain you'll need to manually update the <base href...
angular cli Installation error: permission denied for node-sas
sudo npm install -g --unsafe-perm --verbose @angular/cli Installation error (node-sass) with: node v...
angular cli ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Instead of use ng build --prod use ng build --env=prod UPDATE As many of us (thx) have mention this ...
angular cli Property 'controls' does not exist on type 'AbstractControl'.
Got it! Looked at the docs - FormArray The FormArray class contains the controls property ...
angular cli [Bug] cli needs to be reloaded when a lazy loaded module is added in routes (FIXED)
I recomended change { path: 'user-panel' loadChildren: './user-panel/user-panel.module#UserPanelModu...
angular cli AOT build fails
I noticed same problem and after npm i enhanced-resolve@3.3.0 I can build with AOT ...
angular cli Cannot find name 'require'. using relative paths...
Ahhh here we go try adding declare var require: any; To src/typings.d.ts I am using a config with re...
angular cli "No NgModule metadata found for 'AppModule'" after Upgrade to Angular 5.1.0 and AngularCli 1.6.0
I got the same error The issue is fixed only when i manually re installed angular/cli The webpack sh...
angular cli ng serve doesn't listen other than localhost
Works with command ng serve --host OS? Windows 7 8 or 10 Linux (which distribution) Mac OSX ...
angular cli ng: command not found
Removing NODE and using NVM instead fixed a lot of issues After installing angular-cli with the help...
angular cli ng build fails with error Cannot find module 'webpack/lib/node/NodeTemplatePlugin' after updating to v1.3.0
I faced this issue many times recently and always the fix worked for me is : Bug Report or Feature R...
angular cli -bash: ng: command not found
This was a pain to figure out Please provide us with the following information: OS? Mac OSX (Seirra)...
angular cli Uncaught TypeError: Cannot read property 'apply' of undefined on new install
Downgraded to zone.js@0.8.5 and the problem disappeared. Bug Report or Feature Request (mark with an...
angular cli I am on Angular 5 and CLI 1.5 and I get an error
I faced this error after updating a non-CLI project to Angular 5 and @ngtools/webpack 1.8.0 ...
angular cli Error in multi styles
Paths in angular-cli.json are relative to the project root (src/ normally) For instance you have the...
angular cli Error loading npm linked custom library with aot
It seems like this is a issue caused by Typescript and not by Angular CLI Typescript has problems re...
angular cli Cannot find module '@angular/compiler-cli' when running ng serve
Remove angular-cli from your package.json and replace it with @angular/cli $ npm uninstall angular-c...
angular cli is not a function
I have same issue Finally It looks like caused by a scheme changing The item assets now is an array ...
angular cli ng test ends with "Executed 0 of 0 ERROR"
#2125 see @jtsom 's answer: In the karma.conf.js file add: mime: { 'text/x-typescript': ['ts','tsx']...
angular cli Error while installing @angular/cli on AWS Ubuntu 16.04 server
This seems to be a problem with installing which is one of the dep...
angular cli Existing App does not get Service Worker capabilities
I also had this issue the culprit seams to be angularFire2 I worked around it by registering the ser...
angular cli -Webkit-Line-Clamp Not Working in Angular 6
@briantq can you try this? I took it from here I'm submitting a.. Current behavior In Angular 5 ...
angular cli error TS2554: Expected 2 arguments, but got 1 in v8
Before: @ViewChild('foo') foo: ElementRef; After: // query results available in ngOnInit @ViewChild(...
angular cli SCSS "Module not found: Error: Can't resolve" for @font-face url with relative path
Searched around and apparently this is just how sass loader works: sass/sass#1015 There's a suggesti...
angular cli Lazy loading module broken with " No module factory available for dependency type: ContextElementDependency"
fixed : npm uninstall --save-dev webpack sudo rm -R node_modules npm install i think its not lazy lo...
angular cli Angular-cli 6 and base-href no longer supported?
hi thanks for you hint Versions Repro steps change index.html e.g ...
angular cli An unhandled exception while Generating ES5 bundles
I was able to fix my build by for the moment changing the target from es2015 back ...
angular cli Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
npm install enhanced-resolve@3.3.0 Did the trick for me Bug Report or Feature Request (mark with an ...
angular cli Angular 5: NPM Link - model/index.ts is not part of the compilation.
Hey all this is a side effect of the stricter tsconfig as described in
angular cli vendor.bundle.js size is around 10 MB
What command did you run to get these results? ng build by itself does not have any optimizations ...
angular cli How to run jasmine tests without browser ?
Here is how I did it Then I modified the plugins property of the karma.conf.js file adding the Phant...
angular cli Error: dryRunSink.commit(...).ignoreElements(...).concat is not a function
Following this worked - Just Upgraded to Angular CLI: 1.6.4 each time I run ng new I get this error ...
angular cli ProgressPlugin breaks with webpack 4.25.* due to incorrect option colors
Can be fixed temporarily by adding this line to package.json then npm install ...
angular cli Bootstrap styles not loading
I think it is because of the problem with bootstrap try this: Step 1 Hi ...
angular cli Repository is not clean after cli/core update
FYI there is an allow-dirty flag to bypass the repo check. 🐞 Bug report Command (mark with an x) Is...
angular cli ng add @angular/pwa doesn't work correctly in angular-cli 6.2.5 (Maximum call stack size exceeded)
Currently you will need to execute ng add @angular/pwa@v6-lts to ensure the version compatible with ...
angular cli Cannot find module '@angular/tsc-wrapped/src/tsc'
@iaashish i was facing issue - tried following and it worked reinstalled npm to latest version npm u...
angular cli --build-optimizer errors "Cannot read property 'type' of undefined"
I had a similar problem and solved it by replacing import { Observable } from 'rxjs/Rx'; with import...
angular cli ng update did not change my import statements
A workaround for now is to run the following commands after you are already on Angular and CLI versi...
angular cli Can't install angular-cli globally
Try to clean cache npm cache clean uninstall angular-cli npm uninstall -g angular-cli & install agai...
angular cli Error: Module not found: Error: Can't resolve 'fs'
You can fix it just add to the package.json Bug Report or Feature Request (mark with an x) Versions ...
angular cli tsconfig paths and module resolution errors in VS Code
@mehs2690 can you type environment in editor ( don't add import statement yet ) and then press Ctrl ...
angular cli Error on update to Webpack 4.0.1
@DanPride I had the same issue made the same mistake of upgrading webpack independently ...
angular cli Creating new component shows error:TypeError: core_1.PriorityQueue is not a constructor
I had the same issue and solved it by adding devkit-core in version 0.0.29 to my devDependencies or ...
angular cli ng-serve is not working - Could not find module "@angular-devkit/build-angular"
@DineshChopra i've finally made this npm install @angular-devkit/build-angular and it worked I'm won...
angular cli Allowing different HOST headers to be used in ng serve
@ryanper in that example you have the same IP address used for --host and --public-host? If that's t...