gpt4 book ai didi

javascript - 忽略缺少的依赖项

转载 作者:行者123 更新时间:2023-11-28 06:05:05 28 4
gpt4 key购买 nike

我在编译 bundle 时遇到一些问题。基本上我有 webpack 1.13 和 npm3,当我尝试捆绑我的文件时,我收到错误,提示找不到某些依赖项。更具体地说,我导入了 log4js 包,我得到了

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

问题是我的包中不需要所有这些可选模块。 sequelize 也是如此,webpack 尖叫着说我没有它支持的所有驱动程序,即使我需要的只是 mysql 驱动程序。是否有任何配置选项或插件可以忽略所有缺少的依赖项并让 bundle 在没有它们的情况下进行编译?

最佳答案

在 webpack 5 及更高版本中,IgnorePlugin 的用法发生了变化。更新的示例:

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

或者:

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

关于javascript - 忽略缺少的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36938245/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com