我正在构建Angular 7应用程序,当我添加一个包npm install dragula --save并将其导入pollyfills.ts文件时,我会遇到以下错误:

指数js:2未捕获引用错误:未定义全局

当我在谷歌上搜索时,每个人都说要把这个(window as any).global = window;加到pollyfills.ts,我已经做了,但我仍然得到了错误.我还准备删除node_modules文件夹,我也已经这样做了.

我不知道在这里还能做什么.谁能告诉我一些建议,或者至少解释一下为什么会发生这种情况?

这可能不相关,但我也要补充一点.还有一个错误,在我将它们导入pollyfills.ts之前不存在

手风琴组.组成部分ts:9未捕获的引用错误:全局不是

推荐答案

几周前,我遇到了一个类似的问题,当我在polyfills中更改几个集合时,我就解决了这个问题.现在看起来像:

/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js';  // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
// import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';


/**
 * Required to support Web Animations `@angular/platform-browser/animations`.
 * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
 **/
import 'web-animations-js';  // Run `npm install --save web-animations-js`.

/**
 * By default, zone.js will patch all possible macroTask and DomEvents
 * user can disable parts of macroTask/DomEvents patch by setting following flags
 */

 // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
 // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
 // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames

 /*
 * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
 * with the following flag, it will bypass `zone.js` patch for IE/Edge
 */
// (window as any).__Zone_enable_cross_context_check = true;

/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */

(window as any)['global'] = window;

试试这个setts,让我知道.

再看看你的app.module.ts美元——你进口德古拉的方式好吗?

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        ...
        DragulaModule.forRoot(),
        ...
    ],
    exports: [
        ...
    ],
    providers: [
       ...    ],
    bootstrap: [AppComponent]
})

请注意,这应该是应用程序的主app.module.ts,而不是任何子模块或延迟加载的模块.

Typescript相关问答推荐

如何创建泛型类型组件来使用React Native的FlatList或SectionList?'

动态调用类型化函数

在Angular中注入多个BrowserModules,但在我的代码中只有一个

Webpack说你可能需要在Reactjs项目中增加一个加载器''

有没有办法解决这个问题,类型和IntrinsicAttributes类型没有相同的属性?

Angular 错误NG0303在Angular 项目中使用app.Component.html中的NGFor

通过字符串索引访问对象';S的值时出现文字脚本错误

角效用函数的类型推断

如何使所有可选字段在打印脚本中都是必填字段,但不能多或少?

使用2个派生类作为WeakMap的键

如何在ANGLE中注册自定义验证器

以Angular 执行其他组件的函数

vue-tsc失败,错误引用项目可能无法禁用vue项目上的emit

如何将类似数组的对象(字符串::匹配结果)转换为类型脚本中的数组?

如何通过属性名在两个泛型数组中找到匹配的对象?

基于区分的联合键的回调参数缩小

如何使用IsEqual创建断言类型相等的实用程序

如何创建允许使用带有联合类型参数的Array.from()的TS函数?

带动态键的 TS 功能

使用嵌套属性和动态执行时,Typescript 给出交集而不是并集