我正在尝试为我的 Angular 应用程序集成 Karma 和 Jasmine,该应用程序目前处于 v4.1.3
和 TypeScript@2.3.0
并使用 @types
。这个问题不是其他 TS2304
错误的重复,因为我没有遇到“require”或“process”等问题......
当我运行 npm test
时,在一堆组件文件中出现以下错误,
Cannot find name '__metadata'.
Cannot find name '__decorate'.
Cannot find name '__extends'.
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib" : ["es2015.core", "es6", "es7", "dom"],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"sourceMap": true,
"noEmitHelpers": true,
"allowJs" : true,
"types": [
"hammerjs",
"jasmine",
"jquery",
"lodash",
"moment",
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"exclude": [
"node_modules",
"typings"
],
"awesomeTypescriptLoaderOptions": {
"resolveGlobs": true,
"forkChecker": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": { "rewriteTsconfig": false }
}
当我尝试搜索名称时,我没有在 .ts
文件中找到它们。这个错误是从哪里产生的?它来自捆绑的 js 吗?
最佳答案
这些函数是编译器助手。你有 "noEmitHelpers": true
禁用它们的产生导致错误。
TypeScript compiler options
关于javascript - TS2304 : Cannot find name '__decorate' , '__metadata' 和 '__extends',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45290960/