Skip to content

Commit b3476ff

Browse files
clydinvikerman
authored andcommitted
fix(@angular/cli): improve robustness of Node.js version check
This change ensures that both the global version and the project version Node.js version requirements are met before the CLI executes a command. Previously an older global version of the CLI would allow a newer project version to execute even if the project version had more strict Node.js version requirements. The Node.js version is now checked twice. Once in an ES5 safe script to ensure that ancient Node.js versions are not in use. And secondly in the CLI entry code that is executed after global/project bootstrapping.
1 parent c0c13a2 commit b3476ff

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

packages/angular/cli/bin/ng

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
// Due to an obscure Mac bug, do not start this title with any symbol.
66
try {
77
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
8-
} catch(_) {
8+
} catch (_) {
99
// If an error happened above, use the most basic title.
1010
process.title = 'ng';
1111
}
1212

13-
// Some older versions of Node do not support let or const.
14-
var version = process.version.substr(1).split('.');
15-
if (Number(version[0]) < 10 || (Number(version[0]) === 10 && Number(version[1]) < 9)) {
13+
// This node version check ensures that extremely old versions of node are not used.
14+
// These may not support ES2015 features such as const/let/async/await/etc.
15+
// These would then crash with a hard to diagnose error message.
16+
// tslint:disable-next-line: no-var-keyword
17+
var version = process.versions.node.split('.').map(part => Number(part));
18+
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
1619
process.stderr.write(
17-
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI 9.0+.\n' +
18-
'The official Node.js version that is supported is 10.13.0 or greater.\n\n' +
19-
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
20+
'Node.js version ' + process.verson + ' detected.\n' +
21+
'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
22+
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
2023
);
2124

2225
process.exit(3);

packages/angular/cli/lib/cli/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ const isDebug =
2121

2222
// tslint:disable: no-console
2323
export default async function(options: { testing?: boolean; cliArgs: string[] }) {
24+
// This node version check ensures that the requirements of the project instance of the CLI are met
25+
const version = process.versions.node.split('.').map(part => Number(part));
26+
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
27+
process.stderr.write(
28+
`Node.js version ${process.version} detected.\n` +
29+
'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
30+
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
31+
);
32+
33+
return 3;
34+
}
35+
2436
const logger = createConsoleLogger(isDebug, process.stdout, process.stderr, {
2537
info: s => (supportsColor ? s : colors.unstyle(s)),
2638
debug: s => (supportsColor ? s : colors.unstyle(s)),

0 commit comments

Comments
 (0)