npm run build 报错
相关课程截图
相关步骤
相关截图:

报错信息:
LXJ@DESKTOP-U0I6DR1 MINGW64 /c/code/2021_1_4_demo
$ npm run build
> 2021_1_4_demo@1.0.0 build C:\code\2021_1_4_demo
> cross-env NODE_ENV=production webpack --config config/webpack.config.prod.js
Invalid options object. Terser Plugin has been initialized using an options object that does not match the API schema.
- options has an unknown property 'sourceMap'. These properties are valid:
object { test?, include?, exclude?, terserOptions?, extractComments?, parallel?, minify? }
ValidationError: Invalid options object. Terser Plugin has been initialized using an options object that does not match the API schema.
at validate (C:\code\2021_1_4_demo\node_modules\terser-webpack-plugin\node_modules\schema-utils\dist\validate.js:104:11)
at new TerserPlugin (C:\code\2021_1_4_demo\node_modules\terser-webpack-plugin\dist\index.js:118:31)
at Object.<anonymous> (C:\code\2021_1_4_demo\config\webpack.config.prod.js:10:13)
at Module._compile (C:\code\2021_1_4_demo\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (C:\code\2021_1_4_demo\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 2021_1_4_demo@1.0.0 build: `cross-env NODE_ENV=production webpack --config config/webpack.config.prod.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the 2021_1_4_demo@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\LXJ\AppData\Roaming\npm-cache\_logs\2021-01-10T03_43_52_749Z-debug.log
正在回答 回答被采纳积分+1
同样遇到这个问题,最后研究了可能是版本影响,把sourceMap删掉就好了。但是在删掉之后还会报错,报console 的error,同样把compress 里的console删掉,也解决了。
最后prod环境的config变成这样,运行没有错误。
const webpackMerge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.config.base')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const { output } = require('./webpack.config.base')
const webpackconfig = webpackMerge.merge(baseWebpackConfig, {
mode: 'production',
optimization: {
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
warnings:false,
compress:{
warnings:false,
dead_code:true,
drop_debugger: true,
},
output: {
comments:false,
beautify:false,
},
mangle:true,
},
parallel: true,
})
],
splitChunks: {
cacheGroups: {
commons: {
name: 'commons',
chunks: 'initial',
minChunks:3,
enforce: true
}
}
}
}
})
module.exports = webpackconfig


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星