react-native无法解析模块'warnOnce'

时间:2019-11-05 17:05:53

标签: ios react-native

我的英语有点生锈,对此我感到抱歉。

我在iOS模拟器上启动react-native项目时出现错误。

为了排除与代码的任何冲突,我启动了一个新项目

react-native init demo

react-native start 

react-native run-ios --simulator="iPhone 6"

现在是当我收到消息错误

Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module `warnOnce` from `node_modules/react-native/Libraries/react-native/react-native-implementation.js`: warnOnce could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
    at ModuleResolver.resolveDependency (/usr/local/lib/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:186:15)
    at ResolutionRequest.resolveDependency (/usr/local/lib/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/usr/local/lib/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:282:16)
    at Object.resolve (/usr/local/lib/node_modules/react-native/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:426:31
    at Array.map (<anonymous>)
    at resolveDependencies (/usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:423:18)
    at /usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/usr/local/lib/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)

我需要知道是否有人遇到相同的问题以及如何解决?

我的本​​机版本是0.61.5

package.json

{
  "name": "demo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.4"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

感谢您的进阶。

2 个答案:

答案 0 :(得分:1)

metro.config.js修改为

const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
  resolver: {
    blacklistRE: blacklist([
      /node_modules\/.*\/node_modules\/react-native\/.*/,
    ])
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

请参阅thread and answer

答案 1 :(得分:0)

我找到了解决方法。

我正在使用react-native-cli。

最后一本react-native文档中的建议报告告知,react-native-cli可能会导致意外问题。

enter image description here

我删除了react-native-cli,现在使用

npx react-native ...

谢谢,对不起我的英语不好。