webpackbuildwebpack-dev-serverwebpack-4

how solve error jest-worker at run build?


i have a problem at run build production in webpack. but when i run using dev-server, more code can't get error. please help.. I have to finish my last project and it must run with good at production mode. I hope I get a solution from you guys.

here my error at run build:

    /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.

here my 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
  }
}

here my webpack.dev.js

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

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

Solution

  • what's the version of Node.js are you using?

    I ran into the same error when I was running the latest terser-webpack-plugin @ 3.0.2. According to the release log, there were some breaking changes introduced in 3.0.0 and one of them was "minimum supported Node.js version is 10.13"

    It worked when I downgraded terser-webpack-plugin to 2.3.6.

    So you'll probably have to upgrade your Node.js if you're using a version earlier than 10.13, or downgrade your terser-webpack-plugin.