尝试创建发布包时无法解析模块 'AccessibilityInfo'
Unable to resolve module 'AccessibilityInfo', when trying to create release bundle
我是运行
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-*`.
我尝试了互联网上推荐的所有方法,但没有任何效果。我完全坚持它。请帮忙。
npm cache clean --force
为我工作
它不适用于 npm cache clean --force
或重启系统
或删除节点模块并重新安装。
当我们使用最新版本创建新项目时,它似乎工作正常但在升级时一切似乎都停止工作
我建议开始新项目。
如果你是 运行 反应原生版本 0.56.0 然后降级到 0.55.4。
cd "on your project directory"
npm install react-native@0.55.4
想知道原因请关注this issue.
我遇到了同样的问题。
我之前的 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
这似乎是 0.56 中与依赖项相关的错误。 "solution" 是为了找到依赖项版本的正确组合。我们通过完全安装这些版本找到了解决方法:
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
"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
为我工作
react-native 0.56.0 在 Windows 平台中被破坏。
请使用 0.55.4
它将解决您的问题!
尝试以下操作:
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
我也在最新的react-native 0.56.0中发现了bug。我试图降级但仍然不适合我。此问题在 windows 操作系统中不在 mac 中。
简单我试过:
react-native init ProjectName --version=0.55.4
它工作正常。
完美解决
尝试使版本相互兼容以获得最佳方式
这里是the link
并使所有内容保持最新状态,例如 android sdkVersio
,例如 27
或 28
。
到目前为止,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
问题已解决 - 工作 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
最近版本的 react-native 有一个错误。要解决(至少暂时)问题,请使用以下版本的 React 和 React Native。
"react": "^16.4.1",
"react-native": "^0.55.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"]
}
另一种方法:通过以下命令之一卸载 react-native-cli
的全局副本:
yarn global remove react-native-cli
npm uninstall -g react-native-cli
据我所知,您的项目可能会意外地从这个全局安装的包而不是您自己本地安装的包中生成 metro bundler(我使用标准 react-native-xcode.sh
构建脚本遇到过这个),并且当版本不匹配时,它就会成为一个问题。这就是解决我的 react-native v0.51 分支问题所需的全部(当清除缓存并重新安装每个本地节点模块时没有效果)。
我还删除了以下包,这些包在实践中可能不相关:create-react-app
、create-react-native-app
和react-native-macos-cli
。基本上,只需列出所有全局安装的包并卸载任何与 React Native 相关的包。
以下解决了问题:
npm install babel-preset-react-native
尝试 运行 npm run flow
时可能会出现类似的问题。解决方法是
npm install babel-preset-flow
对我来说,我必须将 .babelrc 中的预设 "react-native" 替换为 "module:react-native"
所以 .babelrc :
{
"presets": ["module:react-native"]
}
它会很好地工作
我是运行
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-*`.
我尝试了互联网上推荐的所有方法,但没有任何效果。我完全坚持它。请帮忙。
npm cache clean --force
为我工作
它不适用于 npm cache clean --force 或重启系统 或删除节点模块并重新安装。 当我们使用最新版本创建新项目时,它似乎工作正常但在升级时一切似乎都停止工作
我建议开始新项目。
如果你是 运行 反应原生版本 0.56.0 然后降级到 0.55.4。
cd "on your project directory"
npm install react-native@0.55.4
想知道原因请关注this issue.
我遇到了同样的问题。
我之前的 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
这似乎是 0.56 中与依赖项相关的错误。 "solution" 是为了找到依赖项版本的正确组合。我们通过完全安装这些版本找到了解决方法:
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
"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
为我工作
react-native 0.56.0 在 Windows 平台中被破坏。 请使用 0.55.4
它将解决您的问题!
尝试以下操作:
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
我也在最新的react-native 0.56.0中发现了bug。我试图降级但仍然不适合我。此问题在 windows 操作系统中不在 mac 中。
简单我试过:
react-native init ProjectName --version=0.55.4
它工作正常。
完美解决
尝试使版本相互兼容以获得最佳方式
这里是the link
并使所有内容保持最新状态,例如 android sdkVersio
,例如 27
或 28
。
到目前为止,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
问题已解决 - 工作 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
最近版本的 react-native 有一个错误。要解决(至少暂时)问题,请使用以下版本的 React 和 React Native。
"react": "^16.4.1",
"react-native": "^0.55.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"]
}
另一种方法:通过以下命令之一卸载 react-native-cli
的全局副本:
yarn global remove react-native-cli
npm uninstall -g react-native-cli
据我所知,您的项目可能会意外地从这个全局安装的包而不是您自己本地安装的包中生成 metro bundler(我使用标准 react-native-xcode.sh
构建脚本遇到过这个),并且当版本不匹配时,它就会成为一个问题。这就是解决我的 react-native v0.51 分支问题所需的全部(当清除缓存并重新安装每个本地节点模块时没有效果)。
我还删除了以下包,这些包在实践中可能不相关:create-react-app
、create-react-native-app
和react-native-macos-cli
。基本上,只需列出所有全局安装的包并卸载任何与 React Native 相关的包。
以下解决了问题:
npm install babel-preset-react-native
尝试 运行 npm run flow
时可能会出现类似的问题。解决方法是
npm install babel-preset-flow
对我来说,我必须将 .babelrc 中的预设 "react-native" 替换为 "module:react-native"
所以 .babelrc :
{
"presets": ["module:react-native"]
}
它会很好地工作