question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack5 > webpack.IgnorePlugin failure

See original GitHub issue

Bug report

What is the current behavior?

In the process of learning Webpack 5


> webpack5-ignoreplugin@1.0.0 build
> webpack

asset main.js 628 KiB [emitted] (name: main) 1 related asset
runtime modules 1020 bytes 4 modules
modules by path ./node_modules/moment/dist/locale/*.js 407 KiB 135 modules
./src/index.js 300 bytes [built] [code generated]
./node_modules/moment/dist/moment.js 150 KiB [built] [code generated]
./node_modules/moment/dist/locale/ sync ^\.\/.*$ 3.21 KiB [optional] [built] [code generated]
webpack 5.38.1 compiled successfully in 1237 ms

Expectations for main.js <=170kb

If the current behavior is a bug, please provide the steps to reproduce.

// src/index.js

import moment from 'moment'
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));


// webpack.config.js

const path = require('path')
const webpack = require('webpack');

module.exports = {
  mode:'none',
  devtool:'source-map',
  context:process.cwd(),
  entry:'./src/index.js',
  output:{
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
  },
  resolve: {
    modules:['node_modules'],
    mainFields:['jsnext:main','main']
  },
  plugins:[
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  ]
}


What is the expected behavior?

ignore

moment>dist>locale

Other relevant information: webpack version: ^5.38.1 Node.js version: v12.16.3 Operating System: mac 10.15.7 Additional tools:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
myNameIsDucommented, Jun 13, 2021

Yes, feel free to send a PR with fix, just remove it from schema

Sorry, there are some problems mentioned above, should be increased

"required": [ "resourceRegExp"]
"required": [ "checkResource" ]

I will send a PR later

2reactions
jcamdencommented, Jun 20, 2021

Thanks @myNameIsDu . I was intentionally not escaping the periods, but I should have added a glob, and you’re right that my regex probably should include escaped periods to be more specific: (i.e. /.*\.test(\.).*(ts|tsx)$/ ) Here’s what I’m running:

const webpack = require('webpack');

module.exports = {
  future: {
    webpack5: true,
  },
  webpack: (config) => {
    config.plugins.push(
      new webpack.IgnorePlugin({
        resourceRegExp: /.*\.test(\.).*(ts|tsx)$/,
      })
    );
    return config;
  },
};

Seems to work with Webpack 4, but build fails with Webpack 5 enabled:

info  - Creating an optimized production build  
Failed to compile.

HookWebpackError: Cannot read property 'slice' of undefined


> Build error occurred
Error: > Build failed because of webpack errors
    at /home/.../next/dist/build/index.js:17:924
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at runNextTicks (node:internal/process/task_queues:63:3)
    at processImmediate (node:internal/timers:437:9)
    at async Span.traceAsyncFn (/home/...trace.js:6:584)

I assume this means that the modified Webpack config didn’t add up to a proper array in some regard, but I’m not sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IgnorePlugin - webpack
IgnorePlugin prevents the generation of modules for import or require calls matching the regular expressions or filter functions: ...
Read more >
Webpack 5 IgnorePlugin - Not ignoring JS file from output on ...
I am using my Webpack file only to create a CSS file. On build, it outputs a JS file. But I don't want...
Read more >
webpack/webpack - Gitter
Any idea where to start looking for the cause of this error. ... IgnorePlugin(/packery/) but the resulting bundle has errors in it because...
Read more >
How do I ignore an import in webpack? - Reddit
So in fact I would like webpack to ignore completely /opt/nodejs/orm and not even try to pack it. I've tried using the ignore...
Read more >
Webpack: ignore module - remarkablemark
ts file is there which loads the module lazily but IgnorePlugin is not working as expected can you help on the same.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found