VUE2和单元测试:SyntaxError:无法在模块外使用导入语句

发布于 2025-02-11 00:06:50 字数 258 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三生殊途 2025-02-18 00:06:50

我也有同样的问题,就我而言,添加了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!

半枫 2025-02-18 00:06:50

我通过添加以下行来解决我的问题:

transformIgnorePatterns: ['node_modules/(?!module_name)']

在我的jest.config.js文件中

I solve my issue by adding this line:

transformIgnorePatterns: ['node_modules/(?!module_name)']

in my jest.config.js file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文