metro-react-native-babel-preset 找不到



  • {
      "name": "MyGitHub",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
      },
      "dependencies": {
        "metro-react-native-babel-preset": "^0.47.0",
        "prop-types": "^15.6.2",
        "react": "16.3.1",
        "react-native": "^0.55.4",
        "react-native-tab-navigator": "^0.3.4",
        "react-native-vector-icons": "^6.0.0",
        "react-navigation": "^2.13.0"
      },
      "devDependencies": {
        "babel-jest": "23.4.2",
        "babel-preset-react-native": "4.0.0",
        "jest": "23.5.0",
        "react-test-renderer": "16.3.1"
      },
      "jest": {
        "preset": "react-native"
      }
    }
    

    之前运行的好好的,导入react-native-vector-icons之后,就报以下错误。请问是什么问题?

    error: bundling failed: Error: Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "D:\\ProjectSet\\myProject\\reactapp\\MyGitHub\\node_modules\\rea
    ct-native-vector-icons"
        at D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\options\option-manager.js:293:19
        at Array.map (<anonymous>)
        at OptionManager.resolvePresets (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20)
        at OptionManager.mergePresets (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10)
        at OptionManager.mergeOptions (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14)
        at OptionManager.init (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
        at File.initOptions (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\index.js:212:65)
        at new File (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\file\index.js:135:24)
        at Pipeline.transform (D:\ProjectSet\myProject\reactapp\MyGitHub\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    

    .babelrc文件

    {
      "presets": ["react-native"]
    }
    


  • 解决了react-native-vector-icons包下也有一个.babelrc文件,把里面的内容改为和外面一样就好了