In a chroot environment, where /proc etc. is not available, require('os').cpus() returns undefined.
If we run "npm run build" on a Vue.js project, we get the following error:
Building for production.../xxx/node_modules/uglifyjs-webpack-plugin/dist/uglify/index.js:54
this.maxConcurrentWorkers = parallel === true ? _os2.default.cpus().length - 1 : Math.min(Number(parallel) || 0, _os2.default.cpus().length - 1);
^
TypeError: Cannot read property 'length' of undefined
If we change the line 19 of Runner.js from
this.maxConcurrentWorkers = parallel === true ? os.cpus().length - 1 : Math.min(Number(parallel) || 0, os.cpus().length - 1);
to
this.maxConcurrentWorkers = parallel === true ? (os.cpus() !== undefined ? os.cpus().length : 1) - 1 : Math.min(Number(parallel) || 0, (os.cpus() !== undefined ? os.cpus().length : 1) - 1);
it works.
There is only another error in vue-cli (where again some kind of cpu function is used without checking if it returns undefined), but I will open up another support ticket there.
Can you please improve this line of code?