Skip to content

Commit 327d041

Browse files
committed
fix: avoid os.cpus() error in certain envs
close vuejs#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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy