Winnemucca
Winnemucca

Reputation: 3458

VS CODE error S5057 cannot find a tsconfig.json file at the specified directory: '.'

I am having fits getting visual studio code going with my angular 2 starter project.

I have set up my tsconfig.json like so ...

    {
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

Immediately I came across this error

  [ts] Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
class AppComponent

I could not identify what was going on so I ran a build and got this error.

error TS5057: Cannot find a tsconfig.json file at the specified directory: '.'

This error explains why I am getting errors about the component decorator, but I am not sure why the tsconfig.json file is not being found.

I only have one folder and it is holding everything except index.html, package.json and .gitignore.

Upvotes: 16

Views: 19931

Answers (6)

Neurotransmitter
Neurotransmitter

Reputation: 6797

For the most people on Visual Studio Code, it will be sufficient just to create tsconfig.json file in the document root (that's probably where your .ts files are) with simple contents: {}.

This means "an empty JSON file <...>. This will be sufficient for most people."

Upvotes: 8

user3857864
user3857864

Reputation: 29

I am new to Visual Studio Code and had the same problem. I solved it this way: When you define a working folder for your project and add a task, VSC creates an invisible folder called .vscode. Inside that folder, there is where task.json lives and from that point, it is executed.

.vscode (folder)
    task.json
myfolder
    app.ts
    index.html
otherfolder
    newfile.ts
    otherfile.ts
tsconfig.json

the position of the tsconfig.json file is at the same level of the vscode folder. This is what "args": ["."], means at the task.json file.

Just put the tsconfig.json at the expected location

Upvotes: 0

meDev
meDev

Reputation: 907

I got similar error. Solved by changing following line in tasks.json

"args": ["-p", "."],

to

"args": ["-p", "./src"],

In my case tsconfig.json was was in src folder. The Angular 2 project was created using angular-cli.

Upvotes: 12

Howard
Howard

Reputation: 3848

I put the tsconfig.js into the root folder, then I can build my .ts file anywhere in the project folder.

Upvotes: 3

JRoppert
JRoppert

Reputation: 5952

I had the same error when I did the following:

ng new project_name
cd project_name
code .

Opening the src folder instead of the project root folder fixed it:

ng new project_name
cd project_name
code .\src

Upvotes: 1

dmh
dmh

Reputation: 11

Encountered a similar issue.

Tested on Debian 8.4 and Windows 7 SP1, with VS Code versions 1.1.0-insider, 1.0.0, 0.10.8. Also with and without setting typescript.tsdk in .vscode/settings.json.

In all cases, the contents of tsconfig.json seem to be disregarded in favour of the defaults. Running tsc from the terminal, the VS Code tslint plugin, gulp-typescript, and more all make use the file without error, including the modules, decorators, and rules properties.

However, I'm not receiving the TS5057 during a VS Code task managed build unless I rename or remove the file despite the contents being disregarded.

As a temporary measure, you can set typescript.validate.enable to false in your settings and use the tslint plugin for validation while compiling via grunt or gulp, which can be integrated into the task runner if desired.

Upvotes: 1

Related Questions