Error: TSError: ⨯ Failed to compile TypeScript
I ran into the problem:
My project is built in Angular4 using typescript, e2e testing with protractor and karma.
Travis-ci has this error:
[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:
{
"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:
{
"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
npm v3.10.10
Please help me.
source to share
I came here looking for a solution for a similar error, when I updated my typescript version, I didn't have a new project, I am running an angular2 project with "@angular/cli": "1.2.0"
. I updated my version of typescript from 2.0.3
to 2.7.2
and then I have ng e2e
problems like below when starting up 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)
The suggested solutions in this post don't work for me.
I fixed this by updating ts-node
to 5.0.1
. Versions above this were giving errors like the one below when running ng e2e
, even though I experimentalDecorators
set to true
in tsconfig.json
:
Bug TS1219: Experimental decorator support is a feature that may change in a future release. Check the "Experimental Decorators" option to remove this warning
Apart from the above change, I also changed a few lines in protractor.conf.js
Changed:
beforeLaunch: function () {
require('ts-node').register({
project: 'e2e'
});
},
in
beforeLaunch: function () {
require('ts-node/register')
}
This is for people who might stumble upon this post and the suggested solution does not work for them.
source to share
This is my solution for this problem: - Run this command
npm install -save-dev typescript@2.3.4
npm WARN venminder_gui@0.0.1 No repository field.
npm WARN venminder_gui@0.0.1 No license field.
+ typescript@2.3.4
updated 1 package and audited 657 packages in 2.539s
found 0 vulnerabilities
source to share