简体   繁体   中英

Intellij IDEA cannot resolve React Native import

在此处输入图像描述

The React import is ok, but other import can not used in autocompletion.

If I import as import Text from 'react-native' , this can be resolve correctly, but this is incorrect import.So I assume IDE will resolve symbol by lookup import Class name only, The question is how can I work around this?

The problem occurs because of a tricky way react-native modules are defined. I'd suggest using typescript community stubs to solve the issue: Preferences | Languages & Frameworks | JavaScript | Libraries Preferences | Languages & Frameworks | JavaScript | Libraries Preferences | Languages & Frameworks | JavaScript | Libraries , press Download , then choose 'react-native' from the stubs list

I use Webstorm 2017.2 and I experienced this error. I tried various solutions, and following solution was worked on my IDE.

Step 1: This step is optional, but I did it. Remove all of the Webstrom preferences. Please check document for related folders: https://www.jetbrains.com/help/phpstorm/project-and-ide-settings.html

Step 2: Remove .idea file in the project directory.

Step 3: Select React JSX under Languages & Frameworks > JavaScript . 语言和框架> JavaScript

Step 4: Download and select react-native under Languages & Frameworks > JavaScript > Libraries . 语言和框架> JavaScript>库

Step 5: Invalidate Caches / Restart...

无效缓存/重新启动...

最后

This worked for me, go to:

Preferences -> Languages & Frameworks -> JavaScript

and then where it says JavaScript language version , choose in the drop down ReactJSX .

Good luck!

  1. Install flow-typed globally. example: $ npm install -g flow-typed

  2. flow-typed create-stub react-native

  3. open /flow-typed/npm/react-native-vx.xxjs

  4. Copy and paste the entire following code below into react-native.xxx.js.

https://gist.githubusercontent.com/lelandrichardson/c037f46885af67ceb447091c908d1471/raw/829a0e311ce619bbb224cf68780a16753feaf2b6/react-native.js

PS This is the setting when the react-native library component/type cannot be found when designating js as the flow type in the intelliJ platform.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM