React Native Upgrade-最好的transformIgnorePatterns不再起作用?

时间:2018-07-30 21:24:45

标签: react-native babel

我最近升级到RN 0.56.0。我的应用程序运行良好,但是运行测试时,出现错误,这表明我有未以纯JavaScript发行的第三方模块,即使将transformIgnorePatterns应用于有问题的模块后,babel也不似乎无法正常工作。

Test suite failed to run

    SyntaxError: /Users/cobb/develop/my-app/node_modules/react-navigation-props-mapper/index.js: Unexpected token (10:13)

       8 | 
       9 |     if (!SecondOrderWrapperComponent) {
    > 10 |       return <WrappedComponent {...screenProps} {...propsExceptScreenProps} {...params} />;
         |              ^
      11 |     } else {
      12 |       return (
      13 |         <SecondOrderWrapperComponent

      at Parser.raise (node_modules/@babel/parser/lib/index.js:3898:15)
      at Parser.unexpected (node_modules/@babel/parser/lib/index.js:5227:16)
      at Parser.parseExprAtom (node_modules/@babel/parser/lib/index.js:6307:20)
      at Parser.parseExprSubscripts (node_modules/@babel/parser/lib/index.js:5903:21)
      at Parser.parseMaybeUnary (node_modules/@babel/parser/lib/index.js:5882:21)
      at Parser.parseExprOps (node_modules/@babel/parser/lib/index.js:5791:21)
      at Parser.parseMaybeConditional (node_modules/@babel/parser/lib/index.js:5763:21)
      at Parser.parseMaybeAssign (node_modules/@babel/parser/lib/index.js:5710:21)
      at Parser.parseExpression (node_modules/@babel/parser/lib/index.js:5663:21)
      at Parser.parseReturnStatement (node_modules/@babel/parser/lib/index.js:7476:28)

我实际上已经忽略了react-navigation-props-mapper(或者我认为),但是现在无论我做什么,我都会看到相同的错误。

我的.babelrc:

{
  "presets": [
    "react-native"
  ],
  "env": {
    "development": {
      "plugins": [
        "@babel/transform-react-jsx-source",
        "transform-es2015-modules-commonjs"
      ]
    },
    "test": {
      "plugins": [
        "@babel/transform-react-jsx-source",
        "transform-es2015-modules-commonjs"
      ]
    }
  },
  "ignore": [
    "node_modules/aws-sdk"
  ]
}

和package.json:

{
  "name": "pensive-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.55",
    "babel-core": "^7.0.0-0",
    "babel-eslint": "^8.2.2",
    "babel-jest": "^23.4.2",
    "babel-preset-react-native": "^5.0.1",
    "eslint": "^4.18.2",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.9.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    "jest": "^22.4.2",
    "jest-fetch-mock": "^1.4.2",
    "jest-react-native": "^18.0.0",
    "patch-package": "^5.1.1",
    "postinstall-postinstall": "^1.0.0",
    "react-test-renderer": "16.2.0"
  },
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "test": "node node_modules/jest/bin/jest.js",
    "eslint": "./node_modules/.bin/eslint App.js src/**/*.js",
    "postinstall": "patch-package"
  },
  "jest": {
    "preset": "react-native",
    "setupFiles": [
      "./setupJest.js"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}",
      "!**/node_modules/**",
      "!**/vendor/**"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!react-navigation-props-mapper)/"
    ]
  },
  "dependencies": {
    "amazon-cognito-identity-js": "^2.0.19",
    "aws-amplify": "^1.0.4",
    "aws-sdk": "^2.282.1",
    "password-validator": "^4.1.1",
    "prop-types": "^15.6.1",
    "react": "16.4.1",
    "react-native": "0.56.0",
    "react-native-keyboard-aware-scroll-view": "^0.4.4",
    "react-native-loading-spinner-overlay": "^0.5.2",
    "react-native-phone-input": "^0.2.1",
    "react-native-swipeout": "^2.3.3",
    "react-native-tag-select": "^2.0.0",
    "react-native-vector-icons": "^4.6.0",
    "react-navigation": "1.5.11",
    "react-navigation-props-mapper": "^0.2.0",
    "react-redux": "^5.0.7",
    "redux": "^3.7.2"
  }
}

如果我正确地读取了该错误,则似乎是在开玩笑地尝试(em>尝试但失败了),这表明我的.babelrc中可能配置有误。我可以看到这个新的Babel有很多变化,而这些变化仍然是“测试版”。也许我应该坚持使用RN 0.55一段时间?

0 个答案:

没有答案