TSError: ⨯ Unable to compile TypeScript?

See original GitHub issue

I get this weird error by trying to run a simple script:

class Greeter {
  constructor(public greeting: string) { }
  greet() {
    return "<h1>" + this.greeting + "</h1>";
  }
};

var greeter = new Greeter("Hello, world!");

console.log(greeter.greet());

I did:

$ npm install ts-node -g
$ npm install typescript -g
$ ts-node test.ts

And I get the following error:

                          TSError: ⨯ Unable to compile TypeScript
                          examples/echo.ts (2,7): Duplicate identifier 'Greeter'. (2300)
                          at getOutput (/home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:258:17)
                          at /home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:267:16
                          at Object.compile (/home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:403:17)
                          at loader (/home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:289:33)
                          at Object.require.extensions.(anonymous function) [as .ts] (/home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:306:14)
                          at Module.load (module.js:458:32)
                          at tryModuleLoad (module.js:417:12)
                          at Function.Module._load (module.js:409:3)
                          at Function.Module.runMain (module.js:575:10)
                          at Object.<anonymous> (/home/arkotek/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/_bin.ts:179:12)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
Sayan751commented, Dec 16, 2016

I am also facing this issue while running the test cases for my Aurelia ( + Webpack + TypeScript) app. I have already asked about this in stack overflow: http://stackoverflow.com/questions/41137573/karma-error-config-invalid-config-file. As the TypeScript compilation fails from ts-node, the testing can’t proceed further.

I also tried to do a simple ts-node test/unit/setup.ts, and I faced the similar issue with that as well:

C:\Path\to\my\Website>ts-node test/unit/setup.ts

C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:312
          throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
                ^
TSError: ⨯ Unable to compile TypeScript
Cannot find type definition file for 'dir1'. (2688)
Cannot find type definition file for 'dir2'. (2688)
Cannot find type definition file for 'dir3'. (2688)
Cannot find type definition file for 'lang1'. (2688)
Cannot find type definition file for 'dir4'. (2688)
Cannot find type definition file for 'lang2'. (2688)
Cannot find type definition file for 'maps'. (2688)
Cannot find type definition file for 'valueConverters'. (2688)
Cannot find type definition file for 'views'. (2688)
    at getOutput (C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:312:17)
    at C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:343:18
    at Object.compile (C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:502:17)
    at Module.m._compile (C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:406:44)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\spal\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:409:12)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Function.Module.runMain (module.js:604:10)

Any suggestion on what I should look for?

1reaction
blakeembreycommented, Aug 3, 2017

Oh, actually, it is your issue. You need to be in the directory to use the correct tsconfig.json file. This works the same as TypeScript. You’re currently using a different tsconfig.json file which is for ES5 and not ES6 - when you run it in the correct directory it uses the tsconfig.json file from there instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: TSError: ⨯ Unable to compile TypeScript - Stack Overflow
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 ......
Read more >
TSError: ⨯ Unable to compile TypeScript after version `10.1.0 ...
After upgrading from version 10.0.3 to 10.1.0 cypress shows this error. The typescript file seems to be ignored, the project works fine with...
Read more >
I got Unable to compile TypeScript error - CircleCI Discuss
One thing you can do to ensure this is to make sure your executor has Java runtime set up. Based on your config,...
Read more >
Troubleshooting | ts-node - TypeStrong · GitHub
Any error that is not a TSError is from node.js (e.g. SyntaxError ), and cannot be fixed by TypeScript or ts-node. These are...
Read more >
Compiling TypeScript into JavaScript | IntelliJ IDEA ... - JetBrains
IntelliJ IDEA comes with a built-in TypeScript compiler. By default, it outputs generated JavaScript files and sourcemaps next to the TypeScript ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found