reactjs - 语法错误: Unexpected token import with Jest + react-native-animated-ellipsis

标签 reactjs react-native react-redux jestjs react-animated

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

/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 'react'; ^^^^^^ SyntaxError: Unexpected token import

  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"
      ]
    }
  }
}

最佳答案

我不确定为什么你想对你的项目依赖项之一应用 babel 转换,但按照错误消息,即使你想对react-native-animated-ellipsis 应用 babel 转换,你可能应该在 src 上执行此操作并排除 dist 文件夹。

关于reactjs - 语法错误: Unexpected token import with Jest + react-native-animated-ellipsis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691099/

相关文章:

react-native - React Native 卡片样式

javascript - React Native 中带有异步组件的 Redux

javascript - react native 'Cannot read property of undefined' AsyncStorage

reactjs - Webpack 将 React 组件拆分为 "0.js" "1.js"等

react-native - 使用 React Native 向特定用户推送通知

user-interface - 通过 React Native 进行组件叠加

javascript - 如何使用 react 钩子(Hook)验证表单?

javascript - 创建接收包含属性 "props"的 "message"的 React 组件

reactjs - 用户注销(从其他屏幕)时如何重置 TabNavigator

reactjs - React 应用程序登录错误 : Maximum update depth exceeded