[英]Cannot Find Module 'react-native'
After following this article to set up flow, eslint and prettir exactly(but using yarn instead of npm, if that matters).在按照本文设置流程后,eslint 和 prettir 完全相同(但如果重要的话,使用 yarn 而不是 npm)。 I either get module not found error on 'react-native' (which would be gone after installing flow-typed) but either way the file in the "Libraries" of react native called "react-native-implementation.js" has errors on almost every line from "cannot fine module 'invariant', 'warnOnce', 'ActivityIndicator'".
我要么在'react-native'上收到模块未找到错误(安装流式后就会消失)但是无论哪种方式,react native 的“库”中名为“react-native-implementation.js”的文件都有错误几乎每一行都来自“cannot fine module 'invariant', 'warnOnce', 'ActivityIndicator'”。
Even after installing 'flow-typed' and adding stubs error from App.js goes away but the app does not work throwing this error on Metro server即使在安装“flow-typed”并添加来自 App.js 的存根错误消失后,应用程序也无法在 Metro 服务器上抛出此错误
error: bundling failed: Error: Cannot find module 'babel-preset-react-native' from 'C:\PropertyFinder'
- If you want to resolve "react-native", use "module:react-native"
at Function.module.exports [as sync] (C:\PropertyFinder\node_modules\resolve\lib\sync.js:58:15)
at resolveStandardizedName (C:\PropertyFinder\node_modules\@babel\core\lib\config\files\plugins.js:101:31)
at resolvePreset (C:\PropertyFinder\node_modules\@babel\core\lib\config\files\plugins.js:58:10)
at loadPreset (C:\PropertyFinder\node_modules\@babel\core\lib\config\files\plugins.js:77:20)
at createDescriptor (C:\PropertyFinder\node_modules\@babel\core\lib\config\config-descriptors.js:154:9)
at items.map (C:\PropertyFinder\node_modules\@babel\core\lib\config\config-descriptors.js:109:50)
at Array.map (<anonymous>)
at createDescriptors (C:\PropertyFinder\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
at createPresetDescriptors (C:\PropertyFinder\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
This is not only from my old project but the reproduced one too I need flow for better intellisense.这不仅来自我的旧项目,也来自我复制的项目,我需要流程以获得更好的智能感知。
I have fixed the error here are the steps I did(there can be improvements):我已经修复了这里的错误是我所做的步骤(可以改进):
1.As of now, flow's bin version is 0.97.0
and react-native produces ^0.92.0
so in the .flowconfig
I changed it to ^0.97.0 2.Now In the root of you're project create a file flowLibs.js(or anything really).
1.截至目前,flow 的 bin 版本为
0.97.0
并且 react-native 生成^0.92.0
所以在.flowconfig
中我将其更改为 ^0.97.0 2.现在在项目的根目录中创建一个文件flowLibs.js(or anything really).
In the.flowconfig under [libs] paste./flowLibs.js and paste在[libs]下的.flowconfig中粘贴./flowLibs.js并粘贴
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/flowLibs.js
under [ignore] tag.在 [忽略] 标签下。 3.Now in the flowLibs.js file you just created above paste
3.现在在上面粘贴刚刚创建的flowLibs.js文件中
declare module "react-native" { declare module.exports: any; }
or if you have problem with another module then replace react-native with you're module.或者,如果您对另一个模块有疑问,请将 react-native 替换为您的模块。 this also fixes the error cannot resolve module 'react-native'
这也修复了无法解析模块“react-native”的错误
NOTE: you do not need to install flow-bin注意:您不需要安装 flow-bin
the reason is that flow-type is included with react-native If you have installed flow-language support extension on vs code then latest version of flow-bin client is already present ie As of now 0.97.0原因是 flow-type 包含在 react-native 如果您在 vs code 上安装了 flow-language 支持扩展,那么最新版本的 flow-bin 客户端已经存在,即截至目前 0.97.0
standard fix for npm issues npm 问题的标准修复
$ rm -rf node_modules
$ npm cache clean -f
$ npm install
You are yarn user, so try delete old node_modules folder and re-run installation.你是 yarn 用户,所以尝试删除旧的node_modules文件夹并重新运行安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.