我有 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.json 或 tsconfig.json
要解决此问题,您可以在根目录中添加 jsconfig.json 或 tsconfig.json 并将 baseUrl 设置为 src
{
"compilerOptions": {
"baseUrl": "./src"
}
}
现在删除 .env 中的 NODE_PATH,这不会破坏当前代码中的任何内容,并且会删除警告。
Note:
pathsinjsconfigortsconfigis still not supported in CRA if you are planning to use this feature in your CRA project you have to wait






