最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ignore missing dependencies - Stack Overflow

programmeradmin5浏览0评论

I have some issues with piling my bundle. Basically I have webpack 1.13 and npm3 and when I try to bundle my files I get error that some dependencies are not found. More specifically I imported log4js package and I get

ERROR in ./~/log4js/lib/appenders/hipchat.js
Module not found: Error: Cannot resolve module 'hipchat-client' in c:\vhosts\not
ifications-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/hipchat.js 2:20-45

ERROR in ./~/log4js/lib/appenders/loggly.js
Module not found: Error: Cannot resolve module 'loggly' in c:\vhosts\notificatio
ns-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/loggly.js 3:11-28

ERROR in ./~/log4js/lib/appenders/mailgun.js
Module not found: Error: Cannot resolve module 'mailgun-js' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/mailgun.js 5:14-35

ERROR in ./~/log4js/lib/appenders/slack.js
Module not found: Error: Cannot resolve module 'slack-node' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/slack.js 2:12-33

ERROR in ./~/log4js/lib/appenders/smtp.js
Module not found: Error: Cannot resolve module 'nodemailer' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/smtp.js 4:13-34

The problem is that I don't need all this optional modules in my bundle. The same goes for sequelize where webpack screams that I dont have all the drivers that it supports, even when all I need is mysql driver. Is there any config option or plugin to just ignore all missing dependencies and let the bundle pile without them ?

I have some issues with piling my bundle. Basically I have webpack 1.13 and npm3 and when I try to bundle my files I get error that some dependencies are not found. More specifically I imported log4js package and I get

ERROR in ./~/log4js/lib/appenders/hipchat.js
Module not found: Error: Cannot resolve module 'hipchat-client' in c:\vhosts\not
ifications-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/hipchat.js 2:20-45

ERROR in ./~/log4js/lib/appenders/loggly.js
Module not found: Error: Cannot resolve module 'loggly' in c:\vhosts\notificatio
ns-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/loggly.js 3:11-28

ERROR in ./~/log4js/lib/appenders/mailgun.js
Module not found: Error: Cannot resolve module 'mailgun-js' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/mailgun.js 5:14-35

ERROR in ./~/log4js/lib/appenders/slack.js
Module not found: Error: Cannot resolve module 'slack-node' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/slack.js 2:12-33

ERROR in ./~/log4js/lib/appenders/smtp.js
Module not found: Error: Cannot resolve module 'nodemailer' in c:\vhosts\notific
ations-daemons\node_modules\log4js\lib\appenders
 @ ./~/log4js/lib/appenders/smtp.js 4:13-34

The problem is that I don't need all this optional modules in my bundle. The same goes for sequelize where webpack screams that I dont have all the drivers that it supports, even when all I need is mysql driver. Is there any config option or plugin to just ignore all missing dependencies and let the bundle pile without them ?

Share Improve this question asked Apr 29, 2016 at 12:21 MaksymMaksym 3,4283 gold badges24 silver badges27 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

With webpack 5 and up, the usage of IgnorePlugin has changed. Updated example:

const webpack = require('webpack');
module.exports = {
  plugins: [
    new webpack.IgnorePlugin({ resourceRegExp: /^/u, contextRegExp: /log4js/u })
  ],
};

Or:

const webpack = require('webpack');
module.exports = {
  plugins: [
    new webpack.IgnorePlugin({ resourceRegExp: /^(hipchat-client|loggly|mailgun-js|slack-node|nodemailer)$/u })
  ],
};

I got the same error when I tried to bundle some package that has the dependency on log4j. My webpack version is 4.5.0. Thanks to @Tony Tai Nguyen's answer, I fix the specific error with webpack ignore plugin and add the below config to my webpack.config.js file.

const webpack = require('webpack');
module.exports = {
  plugins: [
    new webpack.IgnorePlugin(/log4j/)
  ],
};

Yup, there's a plugin that can help you with this. You will need to add something like this:

new webpack.IgnorePlugin(new RegExp("/(node_modules|nodemailer)/"))

to your webpack plugins. More information can be found here: https://webpack.github.io/docs/list-of-plugins.html#ignoreplugin

发布评论

评论列表(0)

  1. 暂无评论