node.js 错误:TSError:?无法编译打字稿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44965071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: TSError: ? Unable to compile TypeScript
提问by RicoLiu
I am facing the problem:
我面临的问题:
My Project is built on Angular4 with typescript, e2e testing with protractor & karma.
我的项目建立在 Angular4 上,带有打字稿,e2e 测试与量角器和业力。
Travis-ci has this error:
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.
My tsconfig.json:
我的 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"
]
}
}
My tsconfig.spec.json:
我的 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"
]
}
Node v6.10.3
节点 v6.10.3
npm v3.10.10
npm v3.10.10
Please help me.
请帮我。
采纳答案by Sajin M Aboobakkar
I had met same issue. First I remove ts-node and typescript from package.json. then,
我遇到了同样的问题。首先,我从 package.json 中删除了 ts-node 和 typescript。然后,
npm install ts-node --save-dev
npm install typescript -g
npm install typescript --save-dev
回答by Ashish Ranjan
I came here looking for a solution for a similar error when I updated my typescript version, Mine was not a new project, I am running an angular2 project with "@angular/cli": "1.2.0". I updated my typescript version from 2.0.3to 2.7.2and then I was getting similar issues like below while running ng e2e.
当我更新我的打字稿版本时,我来到这里寻找类似错误的解决方案,我的不是一个新项目,我正在运行一个带有"@angular/cli": "1.2.0". 我将打字稿版本从 更新2.0.3为2.7.2,然后在运行ng e2e.
Error: TSError: ? Unable to compile TypeScript Cannot find type definition file for 'core-js'. (2688) Cannot find type definition file for 'grecaptcha'. (2688) Cannot find type definition file for 'jasmine'. (2688) Cannot find type definition file for 'moment-timezone'. (2688) Cannot find type definition file for 'node'. (2688) Cannot find type definition file for 'q'. (2688)
Error: TSError: ? Unable to compile TypeScript Cannot find type definition file for 'core-js'. (2688) Cannot find type definition file for 'grecaptcha'. (2688) Cannot find type definition file for 'jasmine'. (2688) Cannot find type definition file for 'moment-timezone'. (2688) Cannot find type definition file for 'node'. (2688) Cannot find type definition file for 'q'. (2688)
The proposed solutions in this post didn't work for me.
这篇文章中提出的解决方案对我不起作用。
I fixed it by updating ts-nodeto 5.0.1. Versions above this were giving errors like the one below while running ng e2eeven though I had experimentalDecoratorsset to truein tsconfig.json:
我通过更新ts-node到5.0.1. ng e2e即使我已experimentalDecorators设置为truein ,在此之上的版本在运行时也会出现如下错误tsconfig.json:
error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning
错误 TS1219:对装饰器的实验性支持是一项功能,在未来版本中可能会发生变化。设置 'experimentalDecorators' 选项以删除此警告
Apart from the above change, I also changed few lines in protractor.conf.js
除了上面的改动,我还改动了几行 protractor.conf.js
Changed:
更改:
beforeLaunch: function () {
require('ts-node').register({
project: 'e2e'
});
},
to
到
beforeLaunch: function () {
require('ts-node/register')
}
This is for people who may stumble into this post and the proposed solution doesn't work for them.
这适用于可能偶然发现这篇文章并且提议的解决方案对他们不起作用的人。
回答by Balaji
回答by Khyati Sehgal
This is my solution for this issue: - Run this command
这是我针对此问题的解决方案: - 运行此命令
npm install -save-dev [email protected]
npm install -save-dev [email protected]
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.
+ [email protected]
updated 1 package and audited 657 packages in 2.539s
found 0 vulnerabilities
回答by Deyvison Souto
if only the "npm install -g typescript" doesn't work.
如果只有“npm install -g typescript”不起作用。
try to do "tsc" in the project folder
尝试在项目文件夹中执行“tsc”


