【发布时间】:2019-01-24 15:16:36
【问题描述】:
我正在构建一个 Angular 7 应用程序,当我添加一个包 npm install dragula --save 并将其导入 pollyfills.ts 文件时,我收到此错误:
index.js:2 Uncaught ReferenceError: global is not defined 在 Object../node_modules/custom-event/index.js (index.js:2) 在 webpack_require (bootstrap:83) 在 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 定义 在 Module../src/app/components/accordion/accordion-group.component.ts (手风琴组.component.ts:9) 在 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) 在模块../src/app/app.module.ts (app.constants.ts:17) 在 webpack_require (bootstrap:83) 在模块../src/main.ts (main.ts:1) 在 webpack_require (bootstrap:83)
【问题讨论】:
-
看来“dragula”需要angular polyfill。阅读the docs
-
当我在
import 'dragula';pollyfills.ts中这样做时,这不是我在做什么 -
无论哪种方式,我都建议您使用这样的插件,您将获得更好的回应,提出issue on github 而不是在这里。插件太多了,任何人都知道这个特定的机会很小
-
npm install ng2-dragula是 polyfill 安装它的方式。就像我说的,我不知道这个插件所以¯\_(ツ)_/¯也阅读了设置说明 -
谢谢,我会在github上提出问题并在这里发布结果
标签: node.js angular typescript dragula ng2-dragula