Skip to content

Commit 1e186ea

Browse files
Do not stop process when EPEERINVALID error is raised
In many cases `npm install` command, that CLI calls, will raise EPEERINVALID error (on Linux and Mac OS X). This error code indicates that some of the dependencies have peer dependencies that are not included in the project. Npm 2 considers this case as error and raises EPEERINVALID error. However in npm 3 this case is treated as non-errornous case and instead of EPEERINVALID, only WARNINGIS are shown. CLI uses npm 2 internally (as dependency), so whenever such case happens, it breaks its execution. Until the dependency is updated, let's treat these errors as warnings and continue the execution. After we upgrade the dependency to npm 3 we'll have the same behavior.
1 parent 86ed0d3 commit 1e186ea

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

lib/node-package-manager.ts

+40-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface INpmOpts {
99

1010
export class NodePackageManager implements INodePackageManager {
1111
constructor(private $childProcess: IChildProcess,
12+
private $logger: ILogger,
1213
private $options: IOptions) { }
1314

1415
public getCache(): string {
@@ -37,15 +38,46 @@ export class NodePackageManager implements INodePackageManager {
3738
}
3839

3940
public install(packageName: string, pathToSave: string, config?: any): IFuture<any> {
40-
if (this.$options.disableNpmInstall) {
41-
return Future.fromResult();
42-
}
43-
if (this.$options.ignoreScripts) {
44-
config = config || {};
45-
config["ignore-scripts"] = true;
46-
}
41+
return (() => {
42+
if (this.$options.disableNpmInstall) {
43+
return;
44+
}
45+
if (this.$options.ignoreScripts) {
46+
config = config || {};
47+
config["ignore-scripts"] = true;
48+
}
4749

48-
return this.loadAndExecute("install", [pathToSave, packageName], { config: config });
50+
try {
51+
return this.loadAndExecute("install", [pathToSave, packageName], { config: config }).wait();
52+
} catch (err) {
53+
if (err.code === "EPEERINVALID") {
54+
// Not installed peer dependencies are treated by npm 2 as errors, but npm 3 treats them as warnings.
55+
// We'll show them as warnings and let the user install them in case they are needed.
56+
// The strucutre of the error object in such case is:
57+
// { [Error: The package @angular/[email protected] does not satisfy its siblings' peerDependencies requirements!]
58+
// code: 'EPEERINVALID',
59+
// packageName: '@angular/core',
60+
// packageVersion: '2.1.0-beta.0',
61+
// peersDepending:
62+
// { '@angular/[email protected]': '2.1.0-beta.0',
63+
// '@angular/[email protected]': '2.1.0-beta.0',
64+
// '@angular/[email protected]': '2.1.0-beta.0',
65+
// '@angular/[email protected]': '2.1.0-beta.0',
66+
// '@angular/[email protected]': '2.1.0-beta.0',
67+
// '@angular/[email protected]': '2.1.0-beta.0',
68+
// '@angular/[email protected]': '2.1.0-beta.0',
69+
// '@angular/[email protected]': '2.1.0-beta.0',
70+
// '@ngrx/[email protected]': '^2.0.0',
71+
// '@ngrx/[email protected]': '^2.0.0',
72+
// '[email protected]': '~2.0.0' } }
73+
this.$logger.warn(err.message);
74+
this.$logger.trace("Required peerDependencies are: ", err.peersDepending);
75+
} else {
76+
// All other errors should be handled by the caller code.
77+
throw err;
78+
}
79+
}
80+
}).future<any>()();
4981
}
5082

5183
public uninstall(packageName: string, config?: any, path?: string): IFuture<any> {

0 commit comments

Comments
 (0)