28

I installed typescript globally ( npm install typescript -g )

Then created a folder, ran npm --init, then npm intall typescript --save-dev - it installed typescript@2.1.4

In the folder , I create 'helloworld.ts`

var msg = 'Hello World';
console.log (msg);

ran tsc command with file option - tsc helloworld.ts and see it compiled to helloworld.js.

Next, I want to use tsconfig.json, so I run tsc --init - this doesn't work, says Unknown option 'init'

i say alright, let me try adding tsconfig.json manually and add it in the folder root as below:

{
    "compilerOptions": {
        "target": "es5"
    },
    "files": [
        "helloworld.ts"
    ]
}

and I run tsc on command prompt, but it won't work and outputs me the syntax, example and options of how to use tsc Syntax: tsc [options] [file] ...

whats wrong?

where tsc gives below:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js
C:\Users\Kap\AppData\Roaming\npm\tsc
C:\Users\Kap\AppData\Roaming\npm\tsc.cmd
bnsaa
  • 283
  • 1
  • 3
  • 5

4 Answers4

42

this is the problem:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js

uninstall-update-remove-get-rid-off: Visual Studio outdated extensions...

or remove it from the path ...

or rename the folder to confirm the problem ... then nuke it :)

check what happens if you do:

md x
cd x
tsc --init
npm init -y
npm link typescript
echo console.log('it works') > index.ts
tsc -p .
node .

should output

it works

also. I'll need install typescript local to the project if
a module you depend on, depends on it
you need to use a compiler feature in "your" code
you need to use a different version than the installed globally

to init:

tsc --init

to compile

a 'project' (based on tsconfig.json):

tsc -p .

where . means here

to compile 'other' project

tsc -p other/tsconfig.json

More help

Community
  • 1
  • 1
Dan
  • 2,818
  • 23
  • 21
  • thanks Dan, but it doesn't work for me: `tsc init` yields ` error TS5007: Cannot resolve referenced file: 'init' ` and tsc -p . gives me ` error TS5023: Unknown option 'p' `. I have a feeling that I may have some old version incompatible version of tsc with typescript@2.1.4, but not sure how to fix it, tried uninstalling / reinstalling typescript but no luck so far – bnsaa Dec 23 '16 at 05:44
  • sorry ..my bad , don't know what I was thinking. its "tsc --init", Ill edit the answer, – Dan Dec 23 '16 at 06:12
  • @bnsaa : I see I was thinking ...npm --init is not a flag ;) – Dan Dec 23 '16 at 06:18
  • yup, that was the issue, funny thing , I did removed that from PATH yesterday but still it was not working, so at the end I shut it down and went for sleep, this morning when I started, its working, so I guess it needed a restart :), anyways, thanks Dan – bnsaa Dec 23 '16 at 14:21
  • 2
    for those who may encounter same issue, this is what worked for me - remove/uninstall 'Typescript tools for Visual Studio' from "Windows - Add/Remove Programs". Then remove from the PATH env variable as Dan mentioned above, uninstall typescript `npm uninstall typescript -g`, restart the system and reinstall typescript t `npm install typescript -g`. After this tsc is working all good – bnsaa Dec 23 '16 at 14:25
  • Same problem as original question. I removed the env variable from Path: Microsoft SDKs/Typescript/1.0 - and after 10 attempts remembered that I had to close/reopen my Powershell/command prompt!! But then it worked fine. Thanks for the answer! – Drenai Mar 17 '17 at 13:17
16

The issue I had was that I wasn't getting any errors but I also wasn't getting any output.

I realised that I had "noEmit": true in my tsconfig.json file.

When I removed that it worked as expected :)

Daniel Tonon
  • 9,261
  • 5
  • 61
  • 64
3

What I did to adjust Typescript version of tsc command on my Windows system was:

Editing system environment PATH variable

Removing the Typescript 1.0 path here. (Start button-> Type : environment variables, click on the option (English version of Windows here) and choosing the system environment variable PATH).

Afterwards I entered:

npm link typescript

And then I used the refreshenv command of Chocolatey to refresh the system PATH environment variable I adjusted.

refreshenv

After then running the command: tsc -v I got: Version 2.2.1

The current version of Typescript is 3.5+, but I globally installed Typescript 2.2.1 because I am following a Typescript course using that version.

Tore Aurstad
  • 3,189
  • 1
  • 27
  • 22
  • I had to remove the enviroment variable you've mention directly from Regedit because of the dialog box truncates the value of the PATH variable to 2047 characters. – Hagen Jun 06 '23 at 21:19
3

Every single time I've ended up here after Googling "typescript tsc no output" it's for the same reason. Since this has definitely happened more than once I'll throw my answer into the ring too.

Every time this has happened to me it's because TypeScript is configured with composite: true and I deleted the output directory (the one set as outDir in tsconfig), but didn't delete the tsconfig.tsbuildinfo file.

This leads TypeScript to assume that the output doesn't need updating, because the timestamp on the tsbuildinfo file says that the last build was after all the files were modified.

Jason Kohles
  • 597
  • 5
  • 12