Angular 我需要为ES6配置网页包吗?
我有一个angular应用程序,有一个.tsconfig文件,目标是ES6Angular 我需要为ES6配置网页包吗?,angular,typescript,es6-modules,Angular,Typescript,Es6 Modules,我有一个angular应用程序,有一个.tsconfig文件,目标是ES6 { "compileOnSave": false, "compilerOptions": { "allowJs": true, "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "module": "es2015", "moduleRes
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom",
"es2018.promise"
]
}
}
以下角度组件(Typescript):
通过网页包传输到:
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DispositifsDATIModule", function() { return DispositifsDATIModule; });
它在运行时失败,原因是:
ReferenceError:无法在初始化之前访问“DispositifsDATIModule”
我不知道这里发生了什么
关于ES6的使用,网页包配置中有什么需要更改的吗
编辑:这似乎是ES2015中和/或关于ES2015的一个问题,我想您在这里有循环依赖关系,您的组件文件(假设它是
MyComponent.ts
)从/index.ts
导入DISPOSITIFS\u DATI\u组件,而index.ts
从/MyComponent.ts
导入组件
所以他们相互依赖。在这种情况下,DISPOSITIFS\u DATI\u组件
在使用时无法初始化
为了避免循环依赖,我将把它提取到第三个文件中
UPD:这是一篇有用的文章好吧,这个错误是因为我引用了一个使用TypeScript装饰器的模块而引起的。
我删除了decorators以支持等效的API,问题就消失了
编辑2019年9月4日:
为了清楚起见,我使用的是Angular 7.5,它需要设置为true。
我刚刚了解到,我的外部模块不需要emitdecormatadata
因此,升级到angular 8并将emitDecoratorMetadata设置为false,允许我使用此外部库。谢谢,但在查看我们的代码后,这不是一个循环参考问题。问题已更新。您添加的链接是关于循环依赖项的。他们说“我们这里有循环依赖,但不应该如此”。即使如此,获得错误的唯一方法是循环依赖。从“/index”导入一些东西就像是证据一样。我之所以得到这个错误是因为ts代码中的一个错误。当我导航到路由的url时,它给了我一条更具体的错误消息。
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DispositifsDATIModule", function() { return DispositifsDATIModule; });