错误:TSError:⨯ 无法编译 TypeScript

新手上路,请多包涵

我面临的问题:

我的项目建立在 Angular4 上,带有 typescript,使用量角器和 karma 进行 e2e 测试。

Travis-ci 有这个错误:

 [03:34:54] E/launcher - Error: TSError: ⨯ Unable to compile TypeScript
Cannot find type definition file for 'jasmine'. (2688)
Cannot find type definition file for 'node'. (2688)
e2e/app.e2e-spec.ts (1,32): Cannot find module './app.po'. (2307)
e2e/app.e2e-spec.ts (4,1): Cannot find name 'describe'. (2304)
e2e/app.e2e-spec.ts (7,3): Cannot find name 'beforeEach'. (2304)
e2e/app.e2e-spec.ts (11,3): Cannot find name 'it'. (2304)
e2e/app.e2e-spec.ts (13,5): Cannot find name 'expect'. (2304)

The command "ng e2e" exited with 4.

我的 tsconfig.json:

 {
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": ".",
    "paths": {
      "*": ["./node_modules/*", "*"]
    },
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "types": [ "node", "jasmine" ],
    "typeRoots": [
      "./node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

我的 tsconfig.spec.json:

 {
  "compilerOptions": {
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "target": "es5",
    "baseUrl": "",
    "types": [
      "jasmine",
      "node"
    ],
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts"
  ]
}

节点 v6.10.3

npm v3.10.10

请帮我。

原文由 RicoLiu 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

我遇到了同样的问题。首先,我从 --- 中删除 ts-nodetypescript package.json 。然后,

 npm install ts-node --save-dev
npm install typescript -g
npm install typescript --save-dev

原文由 Sajin M Aboobakkar 发布,翻译遵循 CC BY-SA 4.0 许可协议

就我而言,我只是删除 nodes_modules 目录,然后运行 npm install 命令,它就可以工作了。

原文由 Zakaria Tobbal 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题