Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript compiler (tsc) command not working with tsconfig

Tags:

typescript

tsc

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
like image 911
bnsaa Avatar asked Dec 23 '16 03:12

bnsaa


4 Answers

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

like image 131
Dan Avatar answered Oct 05 '22 02:10

Dan


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

like image 43
Daniel Tonon Avatar answered Oct 05 '22 01:10

Daniel Tonon


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.

like image 44
Tore Aurstad Avatar answered Oct 05 '22 01:10

Tore Aurstad


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.

like image 24
Jason Kohles Avatar answered Oct 05 '22 01:10

Jason Kohles