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

ima*_*uzi 1 build webpack webpack-dev-server webpack-4

我在 webpack 中运行构建生产时遇到问题。但是当我使用 dev-server 运行时,更多的代码不会出错。请帮忙..我必须完成我的最后一个项目,它必须在生产模式下运行良好。我希望我能从你们那里得到解决方案。

这是我在运行构建时的错误:

    /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.
Run Code Online (Sandbox Code Playgroud)

这是我的 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
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 webpack.dev.js

const merge = require('webpack-merge');
const common = require('./webpack.common.js');

module.exports = merge(common, {
    mode: "development",
    devtool: 'inline-source-map'
})
Run Code Online (Sandbox Code Playgroud)

小智 11

您使用的是什么版本的 Node.js?

我在运行最新的 terser-webpack-plugin @ 3.0.2 时遇到了同样的错误。根据发布日志,在 3.0.0 中引入了一些重大更改,其中之一是“最低支持的 Node.js 版本为 10.13”

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

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


Gis*_*has 5

这就是我的工作,对于类似的错误

node_modules/eslint-webpack-plugin/node_modules/jest-worker/build/index.js:110
 _ending;
     ^

SyntaxError: Unexpected token ;
Run Code Online (Sandbox Code Playgroud)

我也使用旧版本的节点,当我这样做时

nvm use 16.15.1
Run Code Online (Sandbox Code Playgroud)

这是我安装的最新版本,它开始工作了。