在React Native中升级Babel后没有名称空间支持吗?

时间:2019-04-18 16:30:42

标签: typescript react-native react-native-android babel

我使用'react-native init --typescript'创建了一个项目,将react-native升级到0.59.5,使用npx babel-upgrade进行了babel,安装并配置了metro-react-native-babel-preset。但是,现在的日志显示不支持名称空间。还有什么我要做的事吗?

我尝试清理npm缓存,删除node_modules目录并重做npm安装。我什至尝试过重建项目。

.babelrc

$ mycli show

package.json

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

我希望项目像以前一样捆绑在一起,但是会出现以下错误

{
  "name": "Ovik",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start --skipflow --reset-cache",
    "develop:android": "react-native run-android --no-packager",
    "develop:ios": "react-native run-ios --no-packager",
    "check": "tsc --noEmit || true"
  },
  "dependencies": {
    "@babel/core": "^7.0.0",
    "babel-loader": "^8.0.5",
    "es6-symbol": "^3.1.1",
    "firebase": "^5.9.4",
    "futura": "^0.2.0",
    "geofire": "^5.0.1",
    "lodash.isequal": "^4.5.0",
    "react": "^16.8.6",
    "react-native": "^0.59.5",
    "react-native-firebase": "^5.3.1",
    "react-native-safe-area-view": "^0.13.1",
    "react-native-slider": "^0.11.0",
    "react-native-typography": "^1.4.0"
  },
  "devDependencies": {
    "@types/lodash.isequal": "^4.5.5",
    "@types/react": "^16.8.13",
    "@types/react-native": "^0.57.45",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^23.4.2",
    "jest": "^24.7.1",
    "metro-react-native-babel-preset": "^0.53.1",
    "patch-package": "^6.1.2",
    "react-native-typescript-transformer": "^1.2.12",
    "react-test-renderer": "^16.8.6",
    "tslint": "^5.16.0",
    "tslint-language-service": "^0.9.9",
    "typescript": "^3.4.3",
    "@babel/preset-flow": "^7.0.0"
  },
  "jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我对React Native的了解是有限的,但是我对转译器/捆绑器确实了解很多。

您的升级显然包括babel的新打字稿预设或transform-typescript插件。就像它说的那样,namespace在babel中不受支持。 babel的原因是按文件进行转换,这与将项目作为一个整体的打字稿不同。

这种警告将继续存在,不太可能在不久的将来得到解决。因此,您要么放弃使用namespace,要么切换回以前的配置并继续使用tsc作为编译器。