Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript can't be compiled in vs code: error TS5007

I just installed vs code v1 (the latest version) and typescript v1.8.10 (latest version). I followed the exact instruction from vs code website but can't get vs code to build the simplest typescript file though I can manually build it by running tsc command in git bash. The output from the vs code is:

error TS5007: Cannot resolve referenced file: '.'.
error TS5023: Unknown option 'p'
Use the '--help' flag to see options.

This is the my helloworld.ts file which really can't be simpler:

class Greet {
    private _message : string;
    constructor(message : string) {
        this._message = message;
    }
    Say = () => console.log(this._message);
}

var g = new Greet('hello typescript!');
g.Say();

This is my tasks.json file:

{
    // See http://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-p", "."],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}

and tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "sourceMap": true
    }
}
like image 800
stt106 Avatar asked Apr 22 '16 17:04

stt106


People also ask

Does VScode support TypeScript?

Visual Studio Code includes TypeScript language support but does not include the TypeScript compiler, tsc . You will need to install the TypeScript compiler either globally or in your workspace to transpile TypeScript source code to JavaScript ( tsc HelloWorld. ts ). You can test your install by checking the version.

How do I select TypeScript version in VS code?

Using the workspace version of TypeScript# You can also trigger the TypeScript version selector with the TypeScript: Select TypeScript Version command. VS Code will automatically detect workspace versions of TypeScript that are installed under node_modules in the root of your workspace.

Does Visual Studio support TypeScript?

TypeScript supportBy default, Visual Studio 2022 provides language support for JavaScript and TypeScript files to power IntelliSense without any specific project configuration. For compiling TypeScript, Visual Studio gives you the flexibility to choose which version of TypeScript to use on a per-project basis.


1 Answers

Maybe it can help as mentioned at (VS Code, error, TS5023) Unknown compiler option 'p'

Open your environment settings and remove the old Typescript from your system PATH variable. Mine was C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\.

  1. Hold Windows Button and hit the PauseBreak key
  2. Advanced System Settings
  3. Environment Variables
  4. In the "System" panel (the bottom in Windows 10) select the Path variable and click Edit
  5. Find and highlight an old version like C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ in the text, delete it. Press "OK" three times.
  6. Restart VS Code
like image 110
finico Avatar answered Sep 29 '22 06:09

finico