最后更新于2022年9月2日 10:18:39
react-route-dom是前端路由的库,在webstorm里面,会用typings来管理一些常用的库的缓存,并且在自动补全的时候优先从这里面找。与此同时,你自己还会在npm里头再下一个最新版的,这就出问题了:
IDE从typings里面找到的版本是5.3.3,但是最新的是6.3.0,最明显的就是没有Routers这个常用的TAG,只有Switch。还就那个恶心。
解决方法:
Webstorm resolve wrong path when using react-router-dom@next
The IDE downloads typings for some popular libraries to its configuration folder and uses it to enhance code completion. You can remove the auto-downloaded typings from your /javascript/typings (https://www.jetbrains.com/help/webstorm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#system-directory) and then either disable typescript.external.type.definitions Registry key or remove react-router-dom from typescript.external.type.definitions.packages
The Registry can be located via: Help > Find action > type Registry…
第一步:从这段得知,在Help > Find action > type Registry...
标签下可以打开Webstorm的注册表,然后:
Cannot resolve symbol ‘Routes’
In the registry, look for typescript.external.type.defintions.packages key and in the value of that field, only remove the react-router-dom field from the values.
Also Go to File -> Invalidate Caches -> select “Clear file system cache and Local History” -> click “Invalidate and Restart”
第二步:在注册表里头的 typescript.external.type.defintions.packages
这个字段下删除react-router-dom
部分
第三步:依次选择File -> Invalidate Caches -> select "Clear file system cache and Local History" -> click "Invalidate and Restart"