SyntaxError:意外的令牌导入与Jest + react-native-animated-省略号 [英] SyntaxError: Unexpected token import with Jest + react-native-animated-ellipsis

查看:101
本文介绍了SyntaxError:意外的令牌导入与Jest + react-native-animated-省略号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的快照测试因react-native失败.我遵循的解决方案很少,但没有任何效果. 我面临的错误是:

My snapshot test is failing with react-native. I have followed few solutions but nothing worked. Error I am facing is:

/Users/USER_NAME/Projects/project_name/node_modules/react-native-animated-省略号/dist/AnimatedEllipsis.js:1 (函数(导出,需求,模块,__ filename,__ dirname){import'react,{Component} from'react'; ^^^^^^ SyntaxError:意外的令牌导入

/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-省略号上进行babel转换时,您可能应该在src上执行此操作,并排除dist文件夹.

I'm not sure why you'd like to apply a babel transformation on one of your project's dependency but following the error message, even if you wanna apply a babel transform on react-native-animated-ellipsis, you should probably do it on the src and exclude the dist folder.

这篇关于SyntaxError:意外的令牌导入与Jest + react-native-animated-省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆