如何将jsconfig.json添加到现有的vscode项目中而不破坏它

Mul*_*lli 4 reactjs visual-studio-code create-react-app vscode-settings

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

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

这里看到了“本地修补程序”来添加base_url ,但是恐怕它将破坏我在其他地方的构建。

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

sau*_*abh 7

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.

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

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

{
  "compilerOptions": {
    "baseUrl": "./src"
  }
}
Run Code Online (Sandbox Code Playgroud)

这将删除警告,你可以继续删除NODE_PATH你的.env,这不会打破当前的代码什么。

注意:如果您打算在CRA项目中使用此功能,则CRA pathsjsconfigtsconfig中仍不支持此功能

  • 您还必须从“.env”中删除“NODE_PATH” (4认同)
  • 仅供参考 - 我已添加此 jsconfig.json 但警告不会消失。 (2认同)