SyntaxError:使用Jest + react-native-animated-ellipsis导入意外的令牌

时间:2018-04-06 10:50:06

标签: reactjs react-native react-redux jest react-animated

我的快照测试失败,反应原生。我遵循了一些解决方案但没有任何效果。 我面临的错误是:

  

/Users/USER_NAME/Projects/project_name/node_modules/react-native-animated-ellipsis/dist/AnimatedEllipsis.js:1       (function(exports,require,module,__ filename,__ dirname){import React,{Component} from'reaction';                                                                     ^^^^^^       SyntaxError:意外的令牌导入

  at node_modules/babel-core/lib/transformation/file/options/option-manager.js:178:20

在我的package.json

"jest": {
    "preset": "react-native",
    "transform": {
      "^.+\\.js?$": "babel-jest"
    },
    "testPathIgnorePatterns": [
      "/node_modules/",
      "Tests/Setup.js"
    ],
    "testMatch": [
      "**/**/__tests__/**/*.js?(x)",
      "**/?(*.)(spec|test).js?(x)"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(react-native|rent-react-native|react-native-navigation|react-native-vector-icons|react-native-maps|react-native-animated-ellipsis)/)"
    ]
  },

.babelrc

{
  "presets": ["react-native"],
  "env": {
    "test": {
      "presets": ["env", "react-native"],
      "plugins": ["react-native-animated-ellipsis"],
      "only": [
        "./**/*.js",
        "node_modules/react-native-animated-ellipsis"
      ]
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我不确定为什么你想对你的一个项目的依赖项应用一个babel变换但是跟着错误信息,即使你想在react-native-animated-ellipsis上应用一个babel变换,你应该在src上执行并排除dist文件夹。