3

在尝试使用 typescript 和 npm 运行我的 Angular2 应用程序时,我收到标题错误。正如在类似主题中所说,我尝试了“import 'reflect-metadata';”但它没有用。

这是我的 package.json 文件中的依赖项:

"reflect-metadata": "0.1.3",

在此先感谢您的时间

PS:这发生在我将应用程序从 rc4 升级到 rc5 之后

编辑 1

有关错误的更多详细信息:

checkReflect    @   vendor.js:40700
(anonymous function)    @   vendor.js:40702
(anonymous function)    @   vendor.js:40791
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:30176
(anonymous function)    @   vendor.js:30215
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:30634
(anonymous function)    @   vendor.js:30652
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:37326
(anonymous function)    @   vendor.js:37842
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:36288
(anonymous function)    @   vendor.js:37305
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:26058
(anonymous function)    @   vendor.js:26118
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:9935
(anonymous function)    @   vendor.js:10294
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:12761
(anonymous function)    @   vendor.js:12871
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:12255
(anonymous function)    @   vendor.js:12657
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:12907
(anonymous function)    @   vendor.js:12935
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:12885
(anonymous function)    @   vendor.js:12892
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:6709
(anonymous function)    @   vendor.js:6746
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   vendor.js:148
(anonymous function)    @   vendor.js:49327
(anonymous function)    @   vendor.js:49528
initModule  @   vendor.js:43
require @   vendor.js:60
expanded    @   vendor.js:34
(anonymous function)    @   main.js:404
initModule  @   vendor.js:43
require @   vendor.js:60
(anonymous function)    @   (index):38
4

2 回答 2

3

当我升级用于休息端点的 swagger 生成的客户端代码(swagger 编辑器 2.2.3)时,我遇到了angular 4.1.3与构建相同的问题。cli

我已经添加reflect-metadata并且它对我有用。之后遇到这个问题的任何人angular 4cli可能对此有所帮助。

错误消息与以下略有不同

_fails.js:1 Uncaught SyntaxError: Unexpected identifier
    at Object../node_modules/core-js/modules/_descriptors.js (_descriptors.js:2)
    at __webpack_require__ (bootstrap aaad282eb132f1a48d07:54)
    at Object../node_modules/core-js/modules/es6.symbol.js (es6.symbol.js:5)
    at __webpack_require__ (bootstrap aaad282eb132f1a48d07:54)
    at Object../node_modules/core-js/es6/symbol.js (polyfills.bundle.js:1560)
    at __webpack_require__ (bootstrap aaad282eb132f1a48d07:54)
    at Object../src/polyfills.ts (ckset.ts:17)
    at __webpack_require__ (bootstrap aaad282eb132f1a48d07:54)
    at Object.2 (polyfills.bundle.js:13849)
    at __webpack_require__ (bootstrap aaad282eb132f1a48d07:54)
core.es5.js:354 Uncaught reflect-metadata shim is required when using class decorators
于 2017-09-19T16:08:30.077 回答
1

控制台中应该有错误来解释为什么reflect-metadata没有加载。

0.1.3 的现有问题是它有条件依赖,可能会被模块化系统(SystemJS、Webpack 等)错误地包含在内。如果脚本以正常方式加载,则不会发生这种情况,

<script src="https://npmcdn.com/reflect-metadata@0.1.3"></script>

以后的包版本应该用于reflect-metadata模块化系统,0.1.8 目前可用。

于 2016-08-20T15:09:14.957 回答