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

标签 reactjs create-react-app visual-studio-code

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

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 here here ,但我担心它会破坏我在其他地方的构建。

在现有项目中解决此问题的最安全方法是什么? jsconfig.json 中还需要哪些额外设置? 或者我应该根本不担心并忽略它?

最佳答案

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.

这是一条警告,指出您在项目中用于绝对路径的方法,即在 .env 中添加 NODE_PATH 将被弃用,转而设置 baseUrl在 jsconfig.jsontsconfig.json

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

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

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

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

关于reactjs - 如何将 jsconfig.json 添加到现有的 vscode 项目而不破坏它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56437517/

相关文章:

javascript - 当axios发出post请求时会发生什么?

javascript - .map() 将错误的值映射到我的 header 标签

visual-studio-code - 如何以编程方式安装所有 VSCode 工作区扩展

c# - Visual Studio Code IntelliSense 建议不会自动弹出

javascript - ReactJS 隐藏 map 函数的第一个 child

reactjs - 如何在localStorage ReactJS中设置aws放大数据

javascript - create-react-app 中未定义 ES6 方法

javascript - 如果不使用导入的数据,是否实际执行导入

reactjs - 代码分割导致 SPA 新部署后无法加载 block

visual-studio-code - 如何在 Visual Studio Code 中更改窗口选项卡字体的大小?