如何将jsconfig.json添加到现有的vscode项目中而不破坏它 [英] How to add jsconfig.json to existing vscode project w/o breaking it

查看:687
本文介绍了如何将jsconfig.json添加到现有的vscode项目中而不破坏它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有React项目,当前未使用 jsconfig.json 文件。
最近,在生成构建(纱线)时收到以下警告消息:

I have React project, currently not using jsconfig.json file. Recently I got the following warning message, when generating a build (yarn):


设置NODE_PATH来解析模块绝对是不赞成在jsconfig.json(如果使用TypeScript,则为tsconfig.json)中设置baseUrl,并将在以后的主要版本的create-react-app中删除。

Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.

我看到本地修补程序添加base_url 这里 这里,但恐怕会破坏我的

I saw "local fixes" to add base_url here here, but I am afraid it will break my build in other places.

在现有项目中解决此问题的最安全方法是什么?
jsconfig.json 需要哪些其他设置?
还是我完全不必担心并忽略它?

What is the safest way to fix this issue in an existing project? What additional settings are required in jsconfig.json? Or should I not worry at all and ignore it?

推荐答案


将NODE_PATH设置为绝对不建议使用resolve模块,因为
赞成在jsconfig.json(如果使用TypeScript是
,则为tsconfig.json)中设置baseUrl,并将在以后的
create-的主要发行版中将其删除。

Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.

这是一条警告,指出您在项目中使用绝对路径的方法,即添加<$ c $建议不要使用 .env 中的c> NODE_PATH ,而建议在 jsconfig.json tsconfig.json

This is a warning stating that the method you use for the absolute path in your project i.e. adding NODE_PATH in your .env will be deprecated, in favor of setting baseUrl in either jsconfig.json or tsconfig.json

要解决此问题,您可以添加 jsconfig .json tsconfig.json 并将根目录设置为 src

To fix this, you can add jsconfig.json or tsconfig.json in your root directory and set the baseUrl as src

{
  "compilerOptions": {
    "baseUrl": "./src"
  }
}

现在删除 NODE_PATH 在你里面r .env ,这不会破坏当前代码中的任何内容,并且会删除警告。

Now remove NODE_PATH in your .env, this won't break anything in your current code and will remove the warning.


注意: jsconfig tsconfig 路径 >如果您打算在CRA项目中使用此功能,则CRA
仍不支持该功能,您必须等待

Note: paths in jsconfig or tsconfig is still not supported in CRA if you are planning to use this feature in your CRA project you have to wait

这篇关于如何将jsconfig.json添加到现有的vscode项目中而不破坏它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆