首页 文章

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

提问于
浏览
4

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

/Users/USER_NAME/Projects/project_name/node_modules/react-native-animated-ellipsis/dist/AnimatedEllipsis.js:1(函数(exports,require,module,__ filename,__ dirname){import React, from'react '; ^^^^^^ SyntaxError: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

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

相关问题