我最近更新到了VSCode 1.6.1,它从Typescript 1.8.10切换到了2.0.3,这使得我的项目停止工作。
反射方法已更改,因此现在Routing-Controllers在尝试获取方法属性时抛出以下错误:
TypeError: Reflect.getMetadata is not a function
at exports.Body (C:\FN\FantasyNation\Stormbringer\node_modules\routing-contr
ollers\decorator\params.js:155:30)
at __param (C:\FN\FantasyNation\Stormbringer\Scripts\controllers\UserControl
ler.js:12:37)
at __decorate (C:\FN\FantasyNation\Stormbringer\Scripts\controllers\UserCont
roller.js:5:110)
at Object.<anonymous> (C:\FN\FantasyNation\Stormbringer\Scripts\controllers\
UserController.js:56:1)按照发行说明中的说明在我的工作区中切换回特定版本,我在工作区中安装了旧的typescript:
npm install typescript@1.8.10 当重新打开VSCode时,没有询问我要使用的TS版本,所以我手动更新了我的工作区"settings.json“来指定它:
{
"files.exclude": {
"**/*.js.map": true,
"**/*.js": {"when": "$(basename).ts"}
},
"editor.stablePeek": true,
"typescript.tsdk": "node_modules/typescript/lib"
}当我打开一个".ts“文件时,VSCode显示了正确的版本:

但是在重新构建(ctrl+shift+B)并再次运行(F5)之后,我仍然得到完全相同的错误。
我的tsconfig是:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"watch": false
},
"exclude": [
"node_modules"
]
}我的启动设置是:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"externalConsole": true,
"sourceMaps": true,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5959
}
]
}我错过了什么吗?
发布于 2016-10-23 00:08:03
嗯,这是一个合并,它弄乱了代码,并移动了导入顺序。
import 'reflect-metadata';应该是让路由控制器正常工作的第一个导入
https://stackoverflow.com/questions/40194095
复制相似问题