javascript - TS2304 : Cannot find name '__decorate' , '__metadata' 和 '__extends'

标签 javascript angular typescript webpack typescript-typings

我正在尝试为我的 Angular 应用程序集成 Karma 和 Jasmine,该应用程序目前处于 v4.1.3TypeScript@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/

相关文章:

javascript - RXJS 缺少throttleWhile 运算符?

javascript - 事件处理程序的状态更新

angular - <ng-select> [items] 值不更新

javascript - 带有 Webpack 的 Typescript 中的环境变量

Angular 2 : AuthGuard not working when using browser navigation buttons

angular - Google 会识别/索引 Angular SPA 模板中的微数据或 RDFa 标记吗?

javascript - 在 Nest.js 中定义 Node 环境

javascript - 如何在滚动时只运行一次 jQuery 动画?

javascript - 在 pg-promise 中使用游标

javascript - 为什么 jQuery dataTables 不能解析我的 JSON?