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: 'monjs2',
},
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
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: 'monjs2',
},
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
Share Improve this question asked Oct 25, 2022 at 11:08 RH-stRH-st 1571 gold badge2 silver badges12 bronze badges 1-
1
If you check the docs you will see IgnorePlugin requires an object as argument, not two regexes. TLDR:
new webpack.IgnorePlugin({resourceRegExp: /\.\/native/, contextRegExp: /\/pg\//});
– Reyno Commented Oct 25, 2022 at 11:11
1 Answer
Reset to default 13Your 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/plugins/ignore-plugin/