npm run build 报错

来源:2-13 koa应用打包优化koa-compose&koa-compress 【实战篇】

qq_麥麥糖_0

2021-01-10 12:27:59

相关课程截图

http://img.mukewang.com/climg/5ffa80c8094a926806740637.jpg

相关步骤

相关截图:

http://img.mukewang.com/climg/5ffa824b093e9f3c08570467.jpg

报错信息:

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


写回答

4回答

LuciusTan

2021-01-21

同样遇到这个问题,最后研究了可能是版本影响,把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


0
hrian
回复
hq_麥麥糖_0
hp>具体的代码仓库~~~

h021-01-28
共2条回复

Brian

2021-01-12

下次除了错误的截图,一定要把代码传上来~~github的地址。

或者把package.json还有webpack的配置代码片段~

node的环境等信息提供出来~

0
hq_麥麥糖_0
hp dir="ltr">好咧,老师,

h021-01-12
共1条回复

qq_麥麥糖_0

提问者

2021-01-11

调试webpage:

http://img.mukewang.com/climg/5ffc704b095cf15206110369.jpg

http://img.mukewang.com/climg/5ffc704b093525ef09780732.jpg


0

qq_麥麥糖_0

提问者

2021-01-11

问题描述补充:在webpack.config.prod.js在生产环境下的webpack打包失败,报错不识别参数‘sourceMap’

0
hq_麥麥糖_0
回复
hrian
hp>好,谢谢老师

h021-02-17
共4条回复

0 学习 · 1842 问题

查看课程

相似问题