更新 react-native-maps 以使用 create-react-native-app

Posted

技术标签:

【中文标题】更新 react-native-maps 以使用 create-react-native-app【英文标题】:update react-native-maps to work with create-react-native-app 【发布时间】:2018-10-27 01:42:04 【问题描述】:

当我运行 create-react-native-app 时,我得到了 react-native-maps 的对等依赖项,以使用 react-native@0.54。我需要能够使用 react-native@0.55.2 和 react@16.3.1

下面是 react-native-maps 的 package.json 文件。注意第 81、82、97 和 98 行

有人可以展示如何编辑这个 json 文件以及如何更新 react-native-maps 吗? 当我尝试:

npm --depth 9999 update

我最终得到了大量关于重复包的错误。


  "_from": "react-native-maps@0.21.0",
  "_id": "react-native-maps@0.21.0",
  "_inBundle": false,
  "_integrity": "sha512-FkCCV1AyaT5ut5ZTKNIdFWBxRUXZovGTydy7U4Cyifj2dv0Q3Sv21B0Myj+aoGhJhvBJzxsU25dDGQN3TP7b/Q==",
  "_location": "/react-native-maps",
  "_phantomChildren": 
    "babel-plugin-check-es2015-constants": "6.22.0",
    "babel-plugin-syntax-async-functions": "6.13.0",
    "babel-plugin-syntax-class-properties": "6.13.0",
    "babel-plugin-syntax-flow": "6.18.0",
    "babel-plugin-syntax-jsx": "6.18.0",
    "babel-plugin-syntax-trailing-function-commas": "6.22.0",
    "babel-plugin-transform-class-properties": "6.24.1",
    "babel-plugin-transform-es2015-arrow-functions": "6.22.0",
    "babel-plugin-transform-es2015-block-scoping": "6.26.0",
    "babel-plugin-transform-es2015-classes": "6.24.1",
    "babel-plugin-transform-es2015-computed-properties": "6.24.1",
    "babel-plugin-transform-es2015-destructuring": "6.23.0",
    "babel-plugin-transform-es2015-for-of": "6.23.0",
    "babel-plugin-transform-es2015-function-name": "6.24.1",
    "babel-plugin-transform-es2015-literals": "6.22.0",
    "babel-plugin-transform-es2015-modules-commonjs": "6.26.2",
    "babel-plugin-transform-es2015-parameters": "6.24.1",
    "babel-plugin-transform-es2015-shorthand-properties": "6.24.1",
    "babel-plugin-transform-es2015-spread": "6.22.0",
    "babel-plugin-transform-es2015-template-literals": "6.22.0",
    "babel-plugin-transform-flow-strip-types": "6.22.0",
    "babel-plugin-transform-object-assign": "6.22.0",
    "babel-plugin-transform-object-rest-spread": "6.26.0",
    "babel-plugin-transform-react-display-name": "6.25.0",
    "babel-plugin-transform-react-jsx": "6.24.1",
    "babel-plugin-transform-react-jsx-source": "6.22.0",
    "babel-plugin-transform-regenerator": "6.26.0",
    "lodash": "4.17.10",
    "react-transform-hmr": "1.0.4"
  ,
  "_requested": 
    "type": "version",
    "registry": true,
    "raw": "react-native-maps@0.21.0",
    "name": "react-native-maps",
    "escapedName": "react-native-maps",
    "rawSpec": "0.21.0",
    "saveSpec": null,
    "fetchSpec": "0.21.0"
  ,
  "_requiredBy": [
    "/expo"
  ],
  "_resolved": "https://registry.npmjs.org/react-native-maps/-/react-native-maps-0.21.0.tgz",
  "_shasum": "005f58e93d7623ad59667e8002101970ddf235c2",
  "_spec": "react-native-maps@0.21.0",
  "_where": "d:\\atestbed\\native-react\\lecture4-contacts\\node_modules\\expo",
  "author": 
    "name": "Leland Richardson",
    "email": "leland.m.richardson@gmail.com"
  ,
  "bugs": 
    "url": "https://github.com/airbnb/react-native-maps/issues"
  ,
  "bundleDependencies": false,
  "dependencies": 
    "babel-plugin-module-resolver": "^2.3.0",
    "babel-preset-react-native": "1.9.0"
  ,
  "deprecated": false,
  "description": "React Native Mapview component for ios + android",
  "devDependencies": 
    "babel-eslint": "^6.1.2",
    "babel-preset-airbnb": "^1.1.1",
    "eslint": "^3.3.1",
    "eslint-config-airbnb": "^10.0.1",
    "eslint-plugin-import": "^1.14.0",
    "eslint-plugin-jsx-a11y": "^2.1.0",
    "eslint-plugin-prefer-object-spread": "^1.1.0",
    "eslint-plugin-react": "^6.1.2",
    "gitbook-cli": "^2.3.0",
    "lodash": "^4.17.2",
    "prop-types": "^15.5.10",
    "react": "^16.3.0-alpha.1",
    "react-native": "^0.54"
  ,
  "homepage": "https://github.com/airbnb/react-native-maps#readme",
  "keywords": [
    "react",
    "react-native",
    "react-component",
    "map",
    "mapview",
    "google-maps",
    "mapkit"
   ],
  "main": "index.js",
  "name": "react-native-maps",
  "peerDependencies": 
    "react": "^16.0",
    "react-native": "^0.51 || ^0.52 || ^0.53 || ^0.54",
    "prop-types": "^15.0 || ^16.0"
  ,
  "repository": 
    "type": "git",
    "url": "git+https://github.com/airbnb/react-native-maps.git"
  ,
  "rnpm": 
    "android": 
      "sourceDir": "./lib/android"
    
  ,
  "scripts": 
    "build": "npm run build:js && npm run build:android && npm run build:ios",
    "build:android": "./gradlew :react-native-maps:assembleDebug",
    "build:ios": "bundle install --path ./example/ios/bundles && bundle exec pod install --project-directory=./example/ios/",
    "build:js": "exit 0",
    "ci": "npm run lint",
    "lint": "eslint ./",
    "preversion": "./scripts/update-version.js",
    "run:android": "./gradlew installDebug && npm run start:android",
    "run:ios": "react-native run-ios --project-path ./example/ios",
    "run:packager": "./node_modules/react-native/packager/packager.sh",
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "start:android": "adb shell am start -n com.airbnb.android.react.maps.example/.MainActivity"
  ,
  "version": "0.21.0"

【问题讨论】:

【参考方案1】:

好的,所以如果我们只是通过以下方式更新 react-native-maps 的 package.json 文件:

under devDependencies:
    "react": "^16.3.1",
    "react-native": "^0.55.2"

under peerDependencies:
    "react": "^16.3.1",
    "react-native": "^0.55",

然后回到顶部项目安装 eslint@4.0.0 和 ajv@6.0.0 并将它们添加到 package.json 中的依赖项中。

【讨论】:

以上是关于更新 react-native-maps 以使用 create-react-native-app的主要内容,如果未能解决你的问题,请参考以下文章

React:如何使用用户当前位置的更新状态而不是初始状态

无法从 react-native-maps 循环多个标记

你能设置 react-native-maps 的初始音高和缩放吗

使用 react-native-maps 未显示谷歌地图/空白

使用未声明的标识符“AIRGoogleMapOverlay”react-native-maps

React Native:对原生依赖使用自动链接“react-native-maps”