简体   繁体   English

WebPack:未捕获的ReferenceError:未定义BrotliBitReader

[英]WebPack: Uncaught ReferenceError: BrotliBitReader is not defined

I am using WebPack to build a module (pdfmake) for the browser. 我正在使用WebPack为浏览器构建模块(pdfmake)。 The dependency chain includes a module called brotli.js which is failing on the following line. 依赖关系链包括一个名为brotli.js的模块,该模块在以下行中失败。

What I'm trying to figure out is why does it throw an exception when BrotliBitReader is clearly defined right above. 我想弄清楚的是,当BrotliBitReader明确定义在上面时,为什么会抛出异常。

Here is a screenshot of the exception (where the breakpoint is): 以下是异常的屏幕截图(断点所在的位置):

Here is full stacktrace: 这是完整的堆栈跟踪:

Here is my WebPack config 这是我的WebPack配置

Thanks for any help! 谢谢你的帮助!

You'll need to add it to the global scope. 您需要将其添加到全局范围。

Try doing something like 尝试做类似的事情

window.BrotliBitReader = function(input) {
    etc...
}

I'm still trying to figure out how Webpack handles things as well, so let me know how that works for you. 我还在试图弄清楚Webpack如何处理事情,所以让我知道它对你有用。

Yes! 是! If you need something that must exist outside of webpack's module scope, then you use externals!!! 如果你需要在webpack的模块范围之外必须存在的东西,那么你使用外部!

To quote our own docs: 引用我们自己的文档:

externals configuration in webpack provides a way of not including a dependency in the bundle. webpack中的externals配置提供了一种不在bundle中包含依赖项的方法。 Instead the created bundle relies on that dependency to be present in the consumers environment. 相反,创建的捆绑包依赖于依赖关系在消费者环境中存在。 This typically applies to library developers though application developers can make good use of this feature too. 这通常适用于库开发人员,尽管应用程序开发人员也可以充分利用此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM