简体   繁体   English

找不到模块'react-native'

[英]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.

相关问题 找不到模块&#39;setupDevtools&#39;React-Native - Cannot find module 'setupDevtools' React-Native BABEL 找不到模块“节点:路径”错误 react-native - BABEL Cannot find module 'node:path' error react-native 错误:找不到模块“ reative-native” /未找到模块:错误:无法解析模块“ react-native-web” - Error: Cannot find module “react-native” / Module not found: Error: Cannot resolve module 'react-native-web' 在 expo react-native 项目中找不到模块“metro/src/lib/TerminalReporter” - Cannot find module 'metro/src/lib/TerminalReporter' in expo react-native project 错误:index.js: [BABEL]: 在 react-native 中找不到模块 'node:fs' - error: index.js: [BABEL]: Cannot find module 'node:fs' in react-native 找不到模块“react-native”的声明文件 - Could not find a declaration file for module 'react-native' 反应本地博览会找不到模块&#39;minizlib&#39; - react native expo Cannot find module 'minizlib' React Native 无法 npx init 项目,找不到模块错误 - React Native cannot npx init project, cannot find module error 运行测试时无法从“node_modules/react-native/jest/setup.js”中找到模块“@babel/runtime/helpers/interopRequireDefault” - Cannot find module '@babel/runtime/helpers/interopRequireDefault' from 'node_modules/react-native/jest/setup.js' when I run tests Babel 模块解析器不适用于 react-native - Babel module resolver not working with react-native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM