我正在构建一个 Angular 7 应用程序,当我添加一个包 npm install dragula --save
并将其导入 pollyfills.ts
文件时,我收到此错误:
index.js:2 Uncaught ReferenceError: global is not defined at Object../node_modules/custom-event/index.js (index.js:2) at webpack_require (bootstrap:83) at Object../node_modules/crossvent/src /crossvent.js (crossvent.js:3) 在 webpack_require (bootstrap:83) 在 Object../node_modules/dragula/dragula.js (dragula.js:4) 在 webpack_require (bootstrap:83) 在 Module../src /polyfills.ts (polyfills.ts:1) 在 webpack_require (bootstrap:83) 在 Object.1 (polyfills.ts:92) 在 webpack_require (bootstrap:83)
当我用谷歌搜索它时,每个人都说将这个 (window as any).global = window;
添加到 pollyfills.ts
我已经这样做了,但我仍然得到错误。我还准备删除 node_modules 文件夹和 npm i
我也这样做了。
我不知道在这里还能做什么。谁能告诉我一些建议或至少解释为什么会发生这种情况?
这可能不相关,但我也会添加它。在我将它们导入到 pollyfills.ts
之前,还有另一个错误不存在
Accordion-group.component.ts:9 Uncaught ReferenceError: global is not defined at Module../src/app/components/accordion/accordion-group.component.ts (accordion-group.component.ts:9) at webpack_require ( bootstrap:83) 在 Module../src/app/components/accordion/accordion.module.ts (accordion.component.ts:10) 在 webpack_require (bootstrap:83) 在 Module../src/app/shared/shared .module.ts (window.extensions.ts:15) 在 webpack_require (bootstrap:83) 在 Module../src/app/app.module.ts (app.constants.ts:17) 在 webpack_require (bootstrap:83)在 Module../src/main.ts (main.ts:1) 在 webpack_require (bootstrap:83)
原文由 3xGuy 发布,翻译遵循 CC BY-SA 4.0 许可协议
几周前我遇到了类似的问题,现在我在 polyfills.ts 中更改了一些设置时解决了它看起来像:
试试这个设置,让我知道。
还请查看您的
app.module.ts
- 您是否以良好的方式导入了 Dragula?请注意,这应该是您的应用程序的主要
app.module.ts
,而不是任何子模块或延迟加载模块。