Solvedangular cli Dependency resolution is broken with 'yarn --pnp' (Yarn Plug 'n' Play)
βοΈ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 thetslib
dependency in itspackage.json
@angular/compiler-cli
also omitstslib
@angular-devkit/build-angular
omitsloader-utils
andsemver
webpack-subresource-integrity
relies on a hack (opened waysact/webpack-subresource-integrity#90)
@angular-devkit/build-angular
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.
require-project-module.js
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?).
@angular-devkit/core/node/resolve.js
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 https://github.com/yarnpkg/berry/releases/tag/2019-08-16
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
- For PnP install strategy via
@yarnpkg/pnpify
tool. - Yarn 2 also supports
node_modules
install strategy vianodeLinker: node-modules
option.
For details please check this pinned issue on Angular CLI:
#16980
Bug Report or Feature Request (mark with an
x
)Command (mark with an
x
)Versions
ng: 6.0.0
yarn: 1.12.0 (RC)
node: v8.11.3
os: OSX 10.13.6
Repro steps
yarn --pnp
(switches it to pnp mode)yarn build
The log given by the failure
Desired functionality
I'd like it work ;) - Specifically when I'm not using yarn pnp, I get this:
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