VUE2和单元测试:SyntaxError:无法在模块外使用导入语句
我正在使用VUE2编写的应用程序的前端进行Vue-Utils进行单位测试。
当我运行测试时,我会收到此错误:SyntaxError:无法在模块外使用导入语句
(我什至不需要测试中的有问题的模块。)
我已经查看了有关该主题的几个答案(包括添加“ type”:package.json中的“模块”或添加扩展名。测试解决方案后的额外错误。 我使用节点/14.19.2。
你有什么想法吗? 我不知道要向您展示哪个文件,请随时向我询问我的代码
I am doing unit tests with vue-utils on the front-end of an application written in vue2.
When I run my test, I get this error: SyntaxError: Cannot use import statement outside a module
(I don't even need the problematic module in my test.)
I have looked at several answers on the subject (including adding "type": "module" in package.json or add extension ".mjs") but I always get an additional error after testing the solution.
I work with node/14.19.2.
Do you have any idea?
I don't know which file to show you, don't hesitate to ask me for my code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也有同样的问题,就我而言,添加了Visual Studio(模块/JS文件)。检查您的VUE/JavaScript代码的顶部,是否有任何导入的文件!
I had a same issue and in my case the Visual Studio added (modules/js file). Check the top of your vue/javascript code, is there any imported file or not!
我通过添加以下行来解决我的问题:
在我的
jest.config.js
文件中I solve my issue by adding this line:
in my
jest.config.js
file