简体   繁体   English

Intellij IDEA 无法解析 React Native 导入

[英]Intellij IDEA cannot resolve React Native import

在此处输入图像描述

The React import is ok, but other import can not used in autocompletion. React import 可以,但其他 import 不能用于自动完成。

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?如果我 import as import Text from 'react-native' ,这可以正确解析,但这是不正确的导入。所以我假设 IDE 将仅通过查找导入类名来解析符号,问题是我该如何解决这个问题?

The problem occurs because of a tricky way react-native modules are defined. 出现问题是因为定义了react-native模块的棘手方法。 I'd suggest using typescript community stubs to solve the issue: Preferences | Languages & Frameworks | JavaScript | Libraries 我建议使用typescript社区存根来解决问题: 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 Preferences | Languages & Frameworks | JavaScript | Libraries ,按Download ,然后从存根列表中选择'react-native'

I use Webstorm 2017.2 and I experienced this error. 我使用Webstorm 2017.2,我遇到了这个错误。 I tried various solutions, and following solution was worked on my IDE. 我尝试了各种解决方案,并在我的IDE上使用了以下解决方案。

Step 1: This step is optional, but I did it. 第1步: 此步骤是可选的,但我做到了。 Remove all of the Webstrom preferences. 删除所有Webstrom首选项。 Please check document for related folders: https://www.jetbrains.com/help/phpstorm/project-and-ide-settings.html 请查看相关文件夹的文档: https//www.jetbrains.com/help/phpstorm/project-and-ide-settings.html

Step 2: Remove .idea file in the project directory. 第2步:删除项目目录中的.idea文件。

Step 3: Select React JSX under Languages & Frameworks > JavaScript . 第3步:语言和框架> JavaScript下选择React JSX。 语言和框架> JavaScript

Step 4: Download and select react-native under Languages & Frameworks > JavaScript > Libraries . 第4步:在“ 语言和框架”>“JavaScript”>“库”下下载并选择react-native。 语言和框架> JavaScript>库

Step 5: Invalidate Caches / Restart... 第5步:使缓存无效/重新启动...

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

最后

This worked for me, go to: 这对我有用,去:

Preferences -> Languages & Frameworks -> JavaScript 首选项 - >语言和框架 - > JavaScript

and then where it says JavaScript language version , choose in the drop down ReactJSX . 然后在它说JavaScript language version ,在下拉ReactJSX选择。

Good luck! 祝好运!

  1. Install flow-typed globally.全局安装流式。 example: $ npm install -g flow-typed示例:$ npm install -g 流式

  2. flow-typed create-stub react-native流式创建存根反应本机

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

  4. Copy and paste the entire following code below into react-native.xxx.js.将下面的全部代码复制并粘贴到 react-native.xxx.js 中。

https://gist.githubusercontent.com/lelandrichardson/c037f46885af67ceb447091c908d1471/raw/829a0e311ce619bbb224cf68780a16753feaf2b6/react-native.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. PS 这是在intelliJ平台指定js为流类型时找不到react-native库组件/类型时的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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