如何解决 运行 构建时的错误 jest-worker?

how solve error jest-worker at run build?

我在 运行 在 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 是什么版本?

我 运行 在 运行 最新的 terser-webpack-plugin @ 3.0.2 时遇到同样的错误。根据发布日志,3.0.0 中引入了一些重大更改,其中之一是 "minimum supported Node.js version is 10.13"

当我将 terser-webpack-plugin 降级到 2.3.6 时它起作用了。

因此,如果您使用的是 10.13 之前的版本,您可能需要升级 Node.js,或者降级您的 terser-webpack-plugin。