【问题标题】:Cannot Find Module 'react-native'找不到模块'react-native'
【发布时间】:2019-09-06 22:30:41
【问题描述】:

在关注 this article 设置 flow、eslint 和 prettir 之后(但使用 yarn 而不是 npm,如果这很重要的话)。我要么在'react-native'上得到模块未找到错误(安装流类型后会消失),但无论哪种方式,react native的“库”中名为“react-native-implementation.js”的文件都有错误几乎每一行都来自“cannot fine module 'invariant', 'warnOnce', 'ActivityIndi​​cator'”。

即使在安装 '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)

这不仅来自我的旧项目,而且是复制的,我需要流以获得更好的智能感知。

【问题讨论】:

    标签: javascript react-native eslint flowtype


    【解决方案1】:

    我已经修复了错误,这里是我做的步骤(可以改进):

    1.截至目前,flow 的 bin 版本为 0.97.0,react-native 生成​​ ^0.92.0,所以在 .flowconfig 中我将其更改为 ^0.97.0 2.现在在你项目的根目录下创建一个文件flowLibs.js(or anything really). 在 [libs] 下的 .flowconfig 中粘贴 ./flowLibs.js 并粘贴

    <PROJECT_ROOT>/node_modules/.*   
    <PROJECT_ROOT>/flowLibs.js
    

    在[忽略]标签下。 3.现在在刚才创建的flowLibs.js文件中粘贴

    declare module "react-native" { declare module.exports: any; }
    

    或者如果你对另一个模块有问题,那么用你的模块替换 react-native。 这也修复了错误 cannot resolve module 'react-native'

    注意:您不需要安装 flow-bin

    原因是 react-native 包含 flow-type 如果你在 vs code 上安装了 flow-language 支持扩展,那么最新版本的 flow-bin 客户端已经存在,即截至目前 0.97.0

    【讨论】:

      【解决方案2】:

      npm 问题的标准修复

      $ rm -rf node_modules
      $ npm cache clean -f
      $ npm install
      

      您是 yarn 用户,所以请尝试删除旧的 node_modules 文件夹并重新运行安装。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-06
        • 1970-01-01
        • 2023-01-18
        • 2016-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多