Error: TSError: ⨯ Unable to compile TypeScript

72,432

Solution 1

I had met same issue. First I remove ts-node and typescript from package.json. then,

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

Solution 2

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.3 to 2.7.2 and then I was getting similar issues like below while running 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 proposed solutions in this post didn't work for me.

I fixed it by updating ts-node to 5.0.1. Versions above this were giving errors like the one below while running ng e2e even though I had experimentalDecorators set to true in 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

Apart from the above change, I also changed few lines in 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.

Solution 3

For me, the solution was changing "jsx": "react-jsx" to "jsx": "react" in the tsconfig.json file.

Share:
72,432
RicoLiu
Author by

RicoLiu

Updated on January 27, 2022

Comments

  • RicoLiu
    RicoLiu over 2 years

    I am facing the problem:

    My Project is built on Angular4 with typescript, e2e testing with protractor & 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.