【问题标题】:Unable to resolve module prop-types, but grep prop-types reveals nothing无法解析模块 prop-types,但 grep prop-types 什么也没显示
【发布时间】:2017-11-11 05:51:01
【问题描述】:

我得到了一个 ios 应用程序的源代码(从 2016 年底开始),我现在正尝试在模拟器中构建和运行它。我只是在学习 React Native。

完整的错误信息在这里:

Unable to resolve module prop-types from /Users/raarts/work/MobileApp/app/node_modules/react-redux/lib/components/Provider.js: Module does not exist in the module map or in these directories:
  /Users/raarts/work/MobileApp/app/node_modules/react-redux/node_modules
,   /Users/raarts/work/MobileApp/app/node_modules

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 packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.

RCTFatal
-[RCTBatchedBridge stopLoadingWithError:]
__25-[RCTBatchedBridge start]_block_invoke_2
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
start

当然,我确实尝试了建议的解决方案,但没有奏效。 我的问题是:我检查了 Provider.js,但该文件中甚至没有出现“prop-types”这个词。

这是 package.json:

{
  "name": "app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "lint": "./node_modules/.bin/eslint index*.js src __tests__",
    "test": "jest"
  },
  "dependencies": {
    "google-libphonenumber": "^2.0.10",
    "prop-types": "^15.5.10",
    "react": "15.4.2",
    "react-native": "0.40.0",
    "react-native-contacts": "^0.7.1",
    "react-native-debug-stylesheet": "^0.1.1",
    "react-native-device-info": "^0.9.7",
    "react-native-i18n": "^0.1.1",
    "react-native-keyboard-aware-scroll-view": "^0.2.8",
    "react-native-modalbox": "^1.3.9",
    "react-native-router-flux": "^3.36.0",
    "react-native-scrollable-tab-view": "^0.7.0",
    "react-native-send-intent": "^1.0.13",
    "react-redux": "^4.4.5",
    "redux": "^3.6.0",
    "redux-actions": "^0.12.0",
    "redux-thunk": "^2.1.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "devDependencies": {
    "babel-eslint": "^7.0.0",
    "babel-jest": "18.0.0",
    "babel-preset-react-native": "1.9.1",
    "chai": "^3.5.0",
    "eslint": "^3.12.1",
    "eslint-plugin-react": "^6.4.1",
    "eslint-plugin-react-native": "^2.2.1",
    "fetch-mock": "^5.6.0",
    "jest": "18.1.0",
    "jest-react-native": "16.0.0",
    "react-test-renderer": "15.4.2",
    "redux-mock-store": "^1.2.1"
  }
}

我搜索了一下,似乎 prop-types 被拆分到一个单独的包中,以替代 React 15.5 弃用的 PropTypes。所以我最初的猜测是一些依赖包正在使用prop-types。但是想象一下,当我为 'prop-types' grep 整个 node_modules 树并且没有在任何地方提到它时(在 eslint-plugin-react 的更改日志中接受)时,我会感到惊讶。

所以现在我很困惑。这里发生了什么?

【问题讨论】:

    标签: react-native


    【解决方案1】:

    你需要 prop-types 模块。

     npm install --save prop-types
    

    【讨论】:

    • @vahdet prop-types 模块未安装在您的应用程序中,这就是显示此错误的原因。如果您安装并重新运行,那么它将解决您的问题。
    【解决方案2】:

    这回答了我的问题:How do I fix RN suddenly being unable to find local modules (Unable to resolve module)?

    原来错误中给出的建议实际上正确的,但我错过了一条错误消息。

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 2017-12-05
      • 2021-10-15
      • 2021-07-27
      • 2017-04-10
      • 2018-09-15
      • 1970-01-01
      • 2021-12-19
      • 2020-11-01
      相关资源
      最近更新 更多