我在webpack中运行构建生产时遇到问题。但是当我使用开发服务器运行时,更多的代码不会出错。请帮助..我必须完成我的上一个项目,并且它必须以良好的生产模式运行。我希望我能从你们那里得到解决方案。
这里是我在运行时的错误:
/MovieDB/node_modules/jest-worker/build/WorkerPool.js:25
} catch {
^
SyntaxError: Unexpected token {
at NativeCompileCache._moduleCompile (/home/donquixote/Desktop/dicoding-submission/MovieDB/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
at Module._compile (/home/donquixote/Desktop/dicoding-submission/MovieDB/node_modules/v8-compile-cache/v8-compile-cache.js:186:36)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
...
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
这里是我的webpack.common.js:
const path = require('path');
const webpack = require('webpack');
const HtmlPackPlugin = require('html-webpack-plugin');
const terserPlugin = require('terser-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new HtmlPackPlugin({
template: './src/index.html',
filename: 'index.html'})
],
optimization: {
minimize: true,
minimizer: [
new terserPlugin({
test: /\.js(\?.*)?$/i,
})
],
sourceMap: true
}
}
这里是我的webpack.dev.js
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: "development",
devtool: 'inline-source-map'
})
您正在使用什么版本的Node.js?
我在运行最新的3.0.2的terser-webpack-plugin时遇到了相同的错误。根据发布日志,3.0.0中引入了一些重大更改,其中之一是“最低支持的Node.js版本为10.13”]
当我将terser-webpack-plugin降级到2.3.6时,它起作用了。
因此,如果您使用的版本早于10.13,则可能必须升级Node.js,或降级terser-webpack-plugin的等级。