如何升级到React Native 0.57.0版本?

时间:2018-09-13 10:27:40

标签: javascript react-native

我用CRNA创建一个项目,然后更改为纯RN项目。

当我键入comman react-native-git-upgrade并运行项目时,显示错误:

error: bundling failed: Error: ENOENT: no such file or directory, open '/Users/motogod19/MyWork/test_upgrade/node_modules/react-native/node_modules/create-react-class/index.js'

升级环境之前:

package.json:

{
  "name": "test_upgrade",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-react-native-stage-0": "^1.0.1",
    "jest": "^23.6.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "16.3.1"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "jest"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "react": "16.3.1",
    "react-native": "~0.55.2"
  }
}

.babelrc:

{
  "presets": [
    "babel-preset-react-native-stage-0/decorator-support"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

升级后:

package.json:

{
  "name": "test_upgrade",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {

    "metro-react-native-babel-preset": "0.45.2",
    "jest": "^23.6.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "16.3.1"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "jest"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "react": "16.5.0",
    "react-native": "~0.57.0"
  }
}

.babelrc:

{
  "presets": [
    "module:metro-react-native-babel-preset"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source"
      ]
    }
  }
}

我不知道如何解决它。在此先感谢您的任何帮助。

步骤1:如果键入npm install create-react-class并运行它会显示错误:

error: bundling failed: Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/motogod19/MyWork/test_up"
    at /Users/motogod19/MyWork/test_up/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19

option-manager.js第293行是:

if (typeof val === "string") {
      presetLoc = (0, _resolvePreset2.default)(val, dirname);

      if (!presetLoc) {
        throw new Error("Couldn't find preset " + (0, _stringify2.default)(val) + " relative to directory " + (0, _stringify2.default)(dirname));
      }

      val = require(presetLoc);
    }

仍然无法弄清楚,谢谢。

2 个答案:

答案 0 :(得分:2)

运行react-native upgrade并运行项目。

如果它不起作用,请手动安装该模块。

npm install create-react-class

然后在代码中的某处添加:

require('create-react-class');

让我知道您是否有任何问题。

答案 1 :(得分:0)

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

安装module:metro-react-native-babel-preset后,需要将其放入.babelrc文件中,而不是“ react-native”,他们对此进行了更改,并且对babel 7进行了很多更改我刚刚进行了更新,并且在模拟器上可以正常工作,但是当我在电话上安装apk时,它立即崩溃,从即时通讯中通过babel助手读取了一些内容……我试图弄清楚这一点。 。但是对于您的问题,这就是答案 https://github.com/facebook/react-native/issues/20150#issue-340235017