webpack 5.21.2 无效的选项对象。忽略插件已使用与 API 架构不匹配的选项对象进行初始化

RH-*_*-st 3 javascript webpack webpack-dev-server

下面是我的webpack.config.jswebpack 版本为 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 */

Run Code Online (Sandbox Code Playgroud)

当尝试部署时,收到以下错误

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

怎么解决啊,非常感谢

Mar*_*ski 9

您没有将正确的对象传递给 IgnorePlugin() 调用。您需要构造一个具有两个特定属性的对象并按如下方式传递该对象

plugins: [new webpack.IgnorePlugin({resourceRegExp: /\.\/native/, contextRegExp: /\/pg\// })],
Run Code Online (Sandbox Code Playgroud)

另请参阅: https: //webpack.js.org/plugins/ignore-plugin/