开发者问题收集

React Native 中未捕获的引用错误?

2018-10-04
1453

为什么我在 React Native 中收到未捕获的引用错误?我能够成功构建,但捆绑器显示此错误。我该如何修复它?

注意:我使用的是 Windows 10

屏幕截图:

在此处输入图片描述

package.json:

{
  "name": "rchampz",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "lodash": "^4.17.11",
    "moment": "^2.22.2",
    "react": "16.5.0",
    "react-native": "0.57.0",
    "react-native-dash": "^0.0.9",
    "react-native-dropdownalert": "^3.5.0",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal-datetime-picker": "^6.0.0",
    "react-native-paper": "^2.0.1",
    "react-native-render-html": "^3.10.0",
    "react-native-timeline-theme": "^0.0.9",
    "react-native-vector-icons": "^5.0.0",
    "react-navigation": "^2.14.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

.babelrc:

{
  "presets": ["module:react-native"]
}
2个回答

在 .bablerc 中包含 react-native 的预设,或者像下面这样从 babel.config.js 导出预设

module.exports = { presets: ['module:metro-react-native-babel-preset'], plugins: [ '@babel/plugin-transform-runtime' ],

Vishal Gupta
2018-10-04

如有疑问,请使用 react-native-cli 创建一个新 ReactNative 项目,并查看构建文件。我刚刚这样做了,这是我所拥有的:

package.json

{
  "name": "someproject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.5.0",
    "react-native": "0.57.1"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.47.1",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

.babelrc :

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

请注意,如果您更改了 package.json,可能需要先进行一些清理

Vinzzz
2018-10-04