VS CODE错误S5057在指定目录中找不到tsconfig.json文件:'。'

时间:2022-05-01 23:37:38

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

我正在使用我的角度2启动项目获得视觉工作室代码。

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

我已经设置了我的tsconfig.json ......

    {
  "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.

此错误解释了为什么我收到有关组件装饰器的错误,但我不确定为什么找不到tsconfig.json文件。

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

我只有一个文件夹,它包含除index.html,package.json和.gitignore之外的所有内容。

6 个解决方案

#1


7  

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: {}.

对于Visual Studio Code上的大多数人来说,只需在文档根目录中创建tsconfig.json文件(这可能就是你的.ts文件所在的位置)就足够了:{}。

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

这意味着“一个空的JSON文件<...>。这对大多数人来说已经足够了。”

Source.

资源。

#2


10  

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

我得到了类似的错误。通过更改tasks.json中的以下行来解决

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

“args”:[“ - p”,“。”],

to

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

“args”:[“ - p”,“。/ src”],

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

在我的情况下tsconfig.json是在src文件夹中。 Angular 2项目是使用angular-cli创建的。

#3


2  

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

我把tsconfig.js放到根文件夹中,然后我可以在项目文件夹中的任何地方构建我的.ts文件。

#4


1  

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:

打开src文件夹而不是项目根文件夹修复它:

ng new project_name
cd project_name
code .\src

#5


0  

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.

在Debian 8.4和Windows 7 SP1上测试,VS Code版本1.1.0-insider,1.0.0,0.10.8。也可以在.vscode / settings.json中设置和不设置typescript.tsdk。

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.

在所有情况下,tsconfig.json的内容似乎被忽略,而不是默认值。从终端运行tsc,VS Code tslint插件,gulp-typescript等都使得文件没有错误,包括模块,装饰器和规则属性。

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.

但是,我在VS代码任务托管构建期间没有收到TS5057,除非我重命名或删除文件,尽管内容被忽略。

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.

作为临时措施,您可以在设置中将typescript.validate.enable设置为false,并在通过grunt或gulp进行编译时使用tslint插件进行验证,如果需要,可以将其集成到任务运行器中。

#6


0  

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.

我是Visual Studio Code的新手并遇到了同样的问题。我这样解决了:当您为项目定义工作文件夹并添加任务时,VSC会创建一个名为.vscode的不可见文件夹。在该文件夹中,task.json就在那里,从那时起,它就被执行了。

.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.

tsconfig.json文件的位置与vscode文件夹的位置相同。这就是“args”:[“。”],表示在task.json文件中。

Just put the tsconfig.json at the expected location

只需将tsconfig.json放在预期的位置即可

#1


7  

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: {}.

对于Visual Studio Code上的大多数人来说,只需在文档根目录中创建tsconfig.json文件(这可能就是你的.ts文件所在的位置)就足够了:{}。

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

这意味着“一个空的JSON文件<...>。这对大多数人来说已经足够了。”

Source.

资源。

#2


10  

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

我得到了类似的错误。通过更改tasks.json中的以下行来解决

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

“args”:[“ - p”,“。”],

to

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

“args”:[“ - p”,“。/ src”],

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

在我的情况下tsconfig.json是在src文件夹中。 Angular 2项目是使用angular-cli创建的。

#3


2  

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

我把tsconfig.js放到根文件夹中,然后我可以在项目文件夹中的任何地方构建我的.ts文件。

#4


1  

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:

打开src文件夹而不是项目根文件夹修复它:

ng new project_name
cd project_name
code .\src

#5


0  

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.

在Debian 8.4和Windows 7 SP1上测试,VS Code版本1.1.0-insider,1.0.0,0.10.8。也可以在.vscode / settings.json中设置和不设置typescript.tsdk。

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.

在所有情况下,tsconfig.json的内容似乎被忽略,而不是默认值。从终端运行tsc,VS Code tslint插件,gulp-typescript等都使得文件没有错误,包括模块,装饰器和规则属性。

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.

但是,我在VS代码任务托管构建期间没有收到TS5057,除非我重命名或删除文件,尽管内容被忽略。

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.

作为临时措施,您可以在设置中将typescript.validate.enable设置为false,并在通过grunt或gulp进行编译时使用tslint插件进行验证,如果需要,可以将其集成到任务运行器中。

#6


0  

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.

我是Visual Studio Code的新手并遇到了同样的问题。我这样解决了:当您为项目定义工作文件夹并添加任务时,VSC会创建一个名为.vscode的不可见文件夹。在该文件夹中,task.json就在那里,从那时起,它就被执行了。

.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.

tsconfig.json文件的位置与vscode文件夹的位置相同。这就是“args”:[“。”],表示在task.json文件中。

Just put the tsconfig.json at the expected location

只需将tsconfig.json放在预期的位置即可