概述

今天在玩 jest 的时候,发现用 import 就会报 Unexpected identifier 的错误。查了很久的资料,最后终于解决了。

参考资料:Jest tests can't process import statement

解决方案

1.首先需要安装下面2个库:

"babel-jest": "^23.6.0",
"babel-core": "7.0.0-bridge.0",

注意版本号一定要和上面的一样,如果版本太高,那就卸载然后重新安装。

2.删掉 node_modules 文件夹,然后安装 yarn ,用 yarn 来安装依赖。

经过试验,第二步不可缺少,只要用 npm 安装都不能解决问题。而且我看见 vue-cli 在安装的时候也会自动使用 yarn,虽然安装完成之后还是可以使用npm。

学到了什么

以后碰到这类关于 npm 包的问题,可以用 yarn 安装试试,反正安装之后仍然可以用 npm。

jest 提示 Unexpected identifier 的解决方案的更多相关文章

  1. JavaScript onclick传递对象参数(easyui传递一行数据时)错误:uncaught SyntaxError: Unexpected identifier

    JavaScript onclick传递对象参数(easyui传递一行数据时)错误:uncaught SyntaxError: Unexpected identifier 博主遇到的是用onclick ...

  2. Unexpected identifier in composer-common/lib/cardstore/businessnetworkcardstore.js:54

    c错误描述 Unexpected identifier in composer-common/lib/cardstore/businessnetworkcardstore.js:54 yo hyper ...

  3. HTML5 plus 报错 Uncaught SyntaxError: Unexpected identifier at XXXX.html:1

    最近使用 VUE2.X + muse-ui  + HTML5 plus 开发webApp 调用HTML5 plus报错,错误提示如下 Uncaught SyntaxError: Unexpected ...

  4. SQL2012 提示评估已过期 解决方案- sql server问题

    SQL2012 提示评估已过期 解决方案提示评估已过期的解决方法和 sql2008一样 第1步:进入SQL2012配置工具中的安装中心第2步:再进入维护界面,选择版本升级第3步:进入产品密钥,输入密钥 ...

  5. Linux启动提示“unexpected inconsistency;RUN fsck MANUALLY”

    问题:在开机启动时,提示“unexpected inconsistency;RUN fsck MANUALLY”进不了系统 解决方法: fsck不仅可以对文件系统进行扫描,还能修正文件系统的一些问题, ...

  6. 从async await 报错Unexpected identifier 谈谈对上下文的理解

    原文首发地址: 先简单介绍下async await: async/await是ES6推出的异步处理方案,目的也很明确:更好的实现异步编程.   详细见阮大神 ES6入门 现在说说实践中遇到的问题:使用 ...

  7. Chrome_调试js出现Uncaught SyntaxError: Unexpected identifier

    转载自:http://blog.csdn.net/yiluoak_47/article/details/7663952 chrome下运行编写的JavaScript代码时,在工具javascript控 ...

  8. [JS]常见JS错误之一:Uncaught SyntaxError: Unexpected identifier

    在编写JS时如果创建变量没有用var而是使用了变量的类型,如: MyClass c=new MyClass(); 这样的错误Java程序员容易犯,也许不经意就写出来了,然后chrome的开发者工具里会 ...

  9. win7访问局域网总提示用户名密码错误解决方案

    win7访问局域网总提示用户名密码错误解决方案 1.点击开始-在搜索栏输入:secpol.msc(或者直接按下win+r键,输入secpol.msc),打开本地安全策略. 2.找到“安全设置”的“本地 ...

随机推荐

  1. webpack搭建前端开发环境

    webpack的版本已经是来到了4.0,口号是无配置就可以使用webpack,当然是使用一些基本的功能 1.安装以下webpack的一些必须npm包 npm install webpack npm i ...

  2. js的小练习

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. python图形图像处理--验证码的制作

    from PIL import Image,ImageDraw,ImageFontimport randomfrom io import BytesIO class code(): def __ini ...

  4. multipart/form-data提交

    pip install requests-toolbelt from requests_toolbelt import MultipartEncoder import requests m = Mul ...

  5. unittest装饰器:只执行一次方法

    @classmethod    def setUpClass(cls):        print "start!" @classmethod    def tearDownCla ...

  6. Linux 开机文件系统发生错误

    1 如果/目录没有损毁,那么开机的时候,屏幕会提示:press root password or ctrl +D,这个时候请输入root密码登陆系统,然后进行如下操作: 1)在光标处输入root密码登 ...

  7. yum 问题

    [root@localhost ~]# yum update There are no enabled repos. Run "yum repolist all" to see t ...

  8. 文件上传 MIME类型检测

    简介 MIME(Multipurpose Internet Mail Extensions)多用途网络邮件扩展类型,可被称为Media type或Content type, 它设定某种类型的文件当被浏 ...

  9. 源于react里面constructor()和super()的使用

    es5里面没有继承的话 //构造函数 function People(name,age){ this.age = age; this.name = name } let p1 = new People ...

  10. 【leetcode】Find K Pairs with Smallest Sums

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...