1

Below is my webpack.config.js in a backend server with webpack version 5.21.1

/* eslint-disable */
const path = require('path');
const webpack = require('webpack');

module.exports = {
  target: 'node',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
    libraryTarget: 'commonjs2',
  },
  plugins: [new webpack.IgnorePlugin(/\.\/native/, /\/pg\//)],
};
/* eslint-enable */

and when trying to deploy, receive error in below

[webpack-cli] Failed to load '/code/webpack.config.js' config
[webpack-cli] Invalid options object. Ignore Plugin has been initialized using an options object that does not match the API schema.
 - options should be one of these:
   object { resourceRegExp, contextRegExp? } | object { checkResource }
   Details:
    * options misses the property 'resourceRegExp'. Should be:
      RegExp
      -> A RegExp to test the request against.
    * options misses the property 'checkResource'. Should be:
      function
      -> A filter function for resource and context.
make: *** [Makefile:8: build] Error 2

How can I fix it, many thanks

RH-st
  • 97
  • 2
  • 10
  • If you check the [docs](https://webpack.js.org/plugins/ignore-plugin/) you will see IgnorePlugin requires an object as argument, not two regexes. TLDR: `new webpack.IgnorePlugin({resourceRegExp: /\.\/native/, contextRegExp: /\/pg\//});` – Reyno Oct 25 '22 at 11:11

1 Answers1

6

Your did not pass a proper object to the IgnorePlugin() call. You need to construct an object with two specific properties and pass that as follows

plugins: [new webpack.IgnorePlugin({resourceRegExp: /\.\/native/, contextRegExp: /\/pg\// })],

See also: https://webpack.js.org/plugins/ignore-plugin/

Martin Lisowski
  • 490
  • 1
  • 3
  • 10