admin管理员组文章数量:1379425
At some point, my VS Code has started to import react hooks from react/cjs/react.production.min
, not from react
.
This annoys me because it only causes errors when I'm developing on my localhost:3000 even with simple hooks such as useState
, useEffect
, etc.. Is there a way to configure VS Code to import React materials from 'react'? I am tired of manually fixing import statements.
The first pic is the error page I get on Next JS, and the second pic is showing how VS Code automatically imports useState from Minified React. The line above it is the ones I manually fixed.
At some point, my VS Code has started to import react hooks from react/cjs/react.production.min
, not from react
.
This annoys me because it only causes errors when I'm developing on my localhost:3000 even with simple hooks such as useState
, useEffect
, etc.. Is there a way to configure VS Code to import React materials from 'react'? I am tired of manually fixing import statements.
The first pic is the error page I get on Next JS, and the second pic is showing how VS Code automatically imports useState from Minified React. The line above it is the ones I manually fixed.
5 Answers
Reset to default 2maybe you can try to install the Auto Import
https://marketplace.visualstudio./items?itemName=steoates.autoimport
or simple reinstall your vscode maybe the fastest way to resolve it
Use:
npm install @types/react -D
Following Rivers answer "Auto Import - ES6, TS, JSX, TSX" worked for me since I don't use Typescript.
https://marketplace.visualstudio./items?itemName=NuclleaR.vscode-extension-auto-import
Apparently, out of nowhere, VS Code started to do the same on my puter -- not suggesting imports from react
package. I tried to install Auto Import but it didn't fix the issue. Thinking about it, I recalled the problem started after the IDE suggested using the Workspace's TypeScript version instead of VS Code's. To fix the issue I did the following:
Open the Command Palette
With Cmd+Shift+P or Ctrl+Shift+P, depending on your OS, and enter "typescript". This will bring up a few suggestions.
Change the TypeScript Version
Press the arrow down (↓) until you reach the TypeScript: Select TypeScript Version... option.
This will bring up another modal to select which version you want to use. In my case, I had the Use Workspace Version option selected. Changing it back to Use VS Code's Version did the trick.
I'm not sure exactly why this was happening -- perhaps there are some settings attached to the editor version -- but trying to import things like useState
or anything from react
package started to work again.
from i use typescript, ide(vscode) start import from react/cjs/react.***.min
. i try to install @types/react, then it working fine
本文标签: javascriptHow to stop VS Code importing react methods from Minified ReactStack Overflow
版权声明:本文标题:javascript - How to stop VS Code importing react methods from Minified React? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744431839a2605987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论