错误:TSError:⨯无法编译TypeScript

Ric*_*Liu 13 node.js travis-ci typescript protractor angular

我正面临着这个问题:

我的项目是建立在Angular4上的打字稿,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.
Run Code Online (Sandbox Code Playgroud)

我的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"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我的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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

节点v6.10.3

npm v3.10.10

请帮我.

Saj*_*kar 8

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

npm install ts-node --save-dev
npm install typescript -g 
npm install typescript --save-dev
Run Code Online (Sandbox Code Playgroud)

  • 只需使用“npm i ts-node@latest”更新 ts-node 对我有用。谢谢。 (8认同)

xyz*_*xyz 7

当我更新我的打字稿版本时,我来到这里寻找类似错误的解决方案,我的不是一个新项目,我正在使用"@angular/cli": "1.2.0". 我将我的打字稿版本从 更新到2.0.32.7.2然后在运行时遇到类似的问题,如下所示ng e2e

\n\n
\n
错误:TSError:\xe2\xa8\xaf 无法编译 TypeScript\n找不到 \'core-js\' 的类型定义文件。(2688)\n无法找到“grecaptcha”的类型定义文件。(2688)\n找不到“jasmine”的类型定义文件。(2688)\n找不到“时刻时区”的类型定义文件。(2688)\n找不到“节点”的类型定义文件。(2688)\n找不到 \'q\' 的类型定义文件。(2688)
\n
\n\n

这篇文章中提出的解决方案对我不起作用。

\n\n

ts-node我通过更新到 来修复它5.0.1ng e2e即使我已experimentalDecorators设置为truein ,上述版本在运行时也会出现如下错误tsconfig.json

\n\n
\n

错误 TS1219:对装饰器的实验性支持是一项功能,可能会在未来版本中发生更改。设置“experimentalDecorators”选项以删除此警告

\n
\n\n

除了上述更改之外,我还更改了几行protractor.conf.js

\n\n

改变:

\n\n
beforeLaunch: function () {\n    require(\'ts-node\').register({\n        project: \'e2e\'\n    });\n},\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
beforeLaunch: function () {\n   require(\'ts-node/register\')\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是针对那些可能偶然发现这篇文章并且建议的解决方案对他们不起作用的人。

\n