29

I installed typescript globally ( npm install typescript -g )

Then created a folder, ran npm --init, then npm intall typescript --save-dev - it installed [email protected]

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

4 Answers 4

44

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

Sign up to request clarification or add additional context in comments.

5 Comments

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 [email protected], but not sure how to fix it, tried uninstalling / reinstalling typescript but no luck so far
sorry ..my bad , don't know what I was thinking. its "tsc --init", Ill edit the answer,
@bnsaa : I see I was thinking ...npm --init is not a flag ;)
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
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
23

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 :)

1 Comment

Saved my day, I mean my evening (dinner)
8

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.

2 Comments

Holy shit man. This was so cryptic. It deserves an issue on Typescript's repo.
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.