Skip to content

Commit 327d041

Browse files
committed
fix: avoid os.cpus() error in certain envs
close #2110
1 parent 70160cc commit 327d041

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/@vue/cli-service/lib/options.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ exports.validate = (options, cb) => {
4747
validate(options, schema, cb)
4848
}
4949

50+
// #2110
51+
// https://github.com/nodejs/node/issues/19022
52+
// in some cases cpus() returns undefined, and may simply throw in the future
53+
function hasMultipleCores () {
54+
try {
55+
return require('os').cpus().length > 1
56+
} catch (e) {
57+
return false
58+
}
59+
}
60+
5061
exports.defaults = () => ({
5162
// project deployment base
5263
baseUrl: '/',
@@ -74,7 +85,7 @@ exports.defaults = () => ({
7485

7586
// use thread-loader for babel & TS in production build
7687
// enabled by default if the machine has more than 1 cores
77-
parallel: require('os').cpus().length > 1,
88+
parallel: hasMultipleCores(),
7889

7990
// multi-page config
8091
pages: undefined,

0 commit comments

Comments
 (0)