【问题标题】:Unable to resolve module 'AccessibilityInfo', when trying to create release bundle尝试创建发布包时无法解析模块“AccessibilityInfo”
【发布时间】:2018-07-23 05:13:33
【问题描述】:

我在跑步

react-native bundle --platform windows --dev false --entry-file index.windows.js --bundle-output windows/app/ReactAssets/index.windows.bundle --assets-dest windows/app/ ReactAssets/

创建发布包的命令,但出现以下错误

Unable to resolve module `AccessibilityInfo` from `C:\Users\godha.pranay\project\node_modules\react-native\Libraries\react-native\react-native-implementation.js`: Module does not exist in the module map



This might be related to https://github.com/facebook/react-native/issues/4968

To resolve try the following:

  1. Clear watchman watches: `watchman watch-del-all`.

  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.

  3. Reset Metro Bundler cache: `rm -rf $TMPDIR/react-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf $TMPDIR/haste-map-react-native-packager-*`.

我尝试了互联网上推荐的所有方法,但没有任何效果。我完全坚持下去。请帮忙。

【问题讨论】:

  • 我也遇到了同样的问题。查了一些资料,发现这个问题应该是0.56版本的bug。

标签: react-native bundle


【解决方案1】:

对我来说,我不得不将 .babelrc 中的预设“react-native”替换为“module:react-native”

所以 .babelrc :

     {
     "presets": ["module:react-native"]
     }

它会正常工作

【讨论】:

    【解决方案2】:

    以下解决了这个问题:

    npm install babel-preset-react-native
    

    尝试运行npm run flow 时可能会出现类似问题。解决方法是

    npm install babel-preset-flow
    

    【讨论】:

    • 你还需要做什么吗?
    【解决方案3】:

    另一种方法:通过以下命令之一卸载 react-native-cli 的全局副本:

    yarn global remove react-native-cli
    npm uninstall -g react-native-cli
    

    据我了解,您的项目可能会意外地从这个全局安装的包而不是您自己本地安装的包中生成 Metro 捆绑器(我使用标准的 react-native-xcode.sh 构建脚本遇到了这个问题),这会成为一个问题当存在版本不匹配时。这就是解决我的 react-native v0.51 分支问题所需的全部内容(当清除缓存并重新安装每个本地节点模块无效时)。

    我还删除了以下软件包,它们可能在实践中不相关:create-react-appcreate-react-native-appreact-native-macos-cli。基本上,只需列出所有全局安装的包并卸载任何与 React Native 相关的包。

    【讨论】:

      【解决方案4】:

      @abinax 的回答对我很有帮助。

      我认为不使用最新的 babel 包,版本号会更合适,因为未来对 babel 的更改可能会破坏现有的兼容性。

      以下是适合我的版本号。

      react-native >> 0.55.4
      babel-core >> 6.26.3
      babel-loader >> 8.0.4
      babel-preset-react-native >> 4.0.0
      

      而@abinax 对版本变化的回答:

      react-native init AwesomeProject
      cd AwesomeProject
      react-native run-android
      npm uninstall react-native
      npm install --save react-native@0.55.4
      react-native run-android
      npm install --save babel-core@6.26.3 babel-loader@8.0.4
      npm uninstall --save babel-preset-react-native
      npm install --save babel-preset-react-native@4.0.0
      react-native run-android
      

      如果遇到此错误,您可能还需要编辑 .babelrc 文件:

      Couldn't find preset "module:metro-react-native-babel-preset" relative to directory  
      

      .babelrc 之前

      {
        "presets": ["module:metro-react-native-babel-preset"]
      }
      

      .babelrc 之后

      {
        "presets": ["react-native"]
      }
      

      【讨论】:

        【解决方案5】:

        我还在最新的 react-native 0.56.0 中发现了错误。我试图降级但仍然不适合我。这个问题在windows操作系统中不在mac中。

        简单我试过:

        react-native init ProjectName --version=0.55.4
        

        它工作正常。

        【讨论】:

          【解决方案6】:

          最近版本的 react-native 有一个错误。要解决(至少暂时)问题,请使用以下版本的 react 和 react native。

          "react": "^16.4.1",
           "react-native": "^0.55.4"
          

          【讨论】:

            【解决方案7】:

            问题已解决 - 100% 正常工作!

            npm remove --save react-native
            npm install --save react-native@0.55.4
            npm remove babel-preset-react-native
            npm install --save babel-preset-react-native@2.1.0
            

            【讨论】:

              【解决方案8】:

              React native + native base + redux + react 兼容版本直到日期。 在 linux 和 Windows 上完美运行。

              package.json

              {
                "name": "ExampleAPP",
                "version": "0.0.1",
                "private": true,
                "scripts": {
                  "start": "node node_modules/react-native/local-cli/cli.js start"
                },
                "dependencies": {
                  "axios": "^0.18.0",
                  "eslint": "^5.2.0",
                  "native-base": "2.6.1",
                  "react": "16.3.1",
                  "react-native": "0.55.4",
                  "react-native-router-flux": "^4.0.1",
                  "react-redux": "^5.0.7",
                  "redux": "^4.0.0",
                  "redux-logger": "^3.0.6",
                  "redux-thunk": "^2.3.0"
                },
              
                }
              }
              

              如果仍然出现错误,请删除 node_modules 文件夹并在项目目录的终端中运行命令

              npm install 
              

              【讨论】:

                【解决方案9】:

                完美解决方案

                尽量使版本相互兼容以达到最佳方式

                这里是the link

                并保持所有内容都是最新的,例如 android sdkVersio,例如 2728

                【讨论】:

                • babel 版本呢,这也很重要。
                • 您还需要将 babel-preset-react-native 版本从 5.0.2 降级到 4.0.0。
                【解决方案10】:

                尝试以下方法:

                npm remove --save react-native
                npm i --save react-native@0.55.4
                npm remove babel-preset-react-native
                npm i --save babel-preset-react-native@2.1.0
                

                【讨论】:

                  【解决方案11】:

                  react-native 0.56.0 在 Windows 平台上被破坏。 请使用 0.55.4

                  它会解决你的问题!

                  【讨论】:

                  • 如果 OP 要求特定版本的 react-native,通常最好帮助 OP 进行设置,而不是推荐其他版本。
                  • @Nerdi.org 然后去为所有答案做同样的评论 :) 因为他们大多说的是一样的
                  • 您的答案出现在官方 SO 审核队列中。我们鼓励留下有用的 cmets / 投票,或在需要主持人时标记。我认为不需要版主,所以我回复了。
                  【解决方案12】:
                      "dependencies": {
                          "react": "^16.4.1",
                          "react-native": "^0.55.4"
                        },
                      "devDependencies": {
                          "babel-preset-react-native": "^4.0.0",
                        },
                  

                  然后点击以下命令

                      npm update
                      npm cache clean --force
                      cd android
                      gradlew clean
                      cd..
                      react-native run-android
                  

                  为我工作

                  【讨论】:

                    【解决方案13】:

                    这似乎是 0.56 中与依赖项相关的错误。 “解决方案”是找到依赖项版本的正确组合。我们通过完全安装这些版本找到了解决方法:

                    react-native >> 0.55.4
                    babel-core >> latest 
                    babel-loader >> latest
                    babel-preset-react-native >> 4.0.0
                    

                    所以你必须按顺序运行这些命令:

                    react-native init AwesomeProject
                    cd AwesomeProject
                    react-native run-android
                    npm uninstall react-native
                    npm install --save react-native@0.55.4
                    react-native run-android
                    npm install --save babel-core@latest babel-loader@latest
                    npm uninstall --save babel-preset-react-native
                    npm install --save babel-preset-react-native@4.0.0
                    react-native run-android
                    

                    【讨论】:

                    • 每次创建新项目时都需要这样做吗?
                    • @PravinsinghWaghela 显然,如果您使用 0.56 版本开始项目,您需要这个。否则,使用 0.55.4 等以前的版本不会导致任何问题。
                    • @MujtabaZaidi 他们修正了 react native 上一个版本的 bug,我强烈建议你移到上一个版本。
                    • 我有 react-native 0.63.4,并收到错误 Unable to resolve module AccessibilityInfo from react-native-calendars/node_modules/react-native/Libraries/react-native/react-native-implementation.js: AccessibilityInfo 在项目中找不到。
                    【解决方案14】:

                    如果您运行的是响应式原生版本 0.56.0,请将其降级到 0.55.4。

                    cd "on your project directory"
                    npm install react-native@0.55.4
                    

                    如果你想知道原因,请关注this issue

                    【讨论】:

                    • 感谢您的解决方案。 react native 最稳定的版本是什么? 0.55.4 似乎很稳定。
                    • 目前我使用的是 0.55.4,但我不确定这是否是稳定版本
                    • 如果我运行的是 0.63.4 怎么办?
                    【解决方案15】:

                    我有同样的问题。

                    我之前的 react-native 版本是

                    C:\WINDOWS\system32>react-native -v
                    react-native-cli: 2.0.1
                    react-native: 0.56.0
                    

                    然后我卸载 react-native

                    C:\WINDOWS\system32>npm uninstall -g react-native-cli
                    removed 41 packages in 3.999s
                    

                    然后我安装了 react-native

                    npm install react-native@0.55.4
                    

                    再次安装

                    npm install -g react-native-cli@1.2.0
                    

                    那么这个创建 react-native 项目的安装就成功了

                    react-native init --version="0.55.4" myprojectname
                    

                    【讨论】:

                    • 在项目初始化之前安装 react-native 对我造成了权限问题。单独在初始化时指定版本就可以了。
                    【解决方案16】:

                    它不适用于 npm cache clean --force 或重启系统 或删除节点模块并重新安装。 当我们使用最新版本创建新项目时,它似乎工作正常,但升级时一切似乎都停止工作

                    我建议开始新项目。

                    【讨论】:

                      【解决方案17】:

                      npm cache clean --force 为我工作

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 2019-01-05
                        • 2023-02-16
                        • 2022-11-02
                        • 1970-01-01
                        • 1970-01-01
                        • 2019-09-12
                        • 2019-12-05
                        相关资源
                        最近更新 更多