[英]How to resolve "SyntaxError: Cannot use import statement outside a module" in jest
I have a react-native application When trying to run yarn jest, I have this error:我有一个 react-native 应用程序在尝试运行 yarn jest 时,出现以下错误:
react native version: "0.64.4"反应本机版本:“0.64.4”
Dependencies:依赖项:
"react-native": "0.64.4", "jest": "29.2.2" “本机反应”:“0.64.4”,“笑话”:“29.2.2”
The test file looks like this:测试文件如下所示:
import 'react-native';
import React from 'react';
import App from '../src/App';
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});`
I tried many solutions but none of them worked for me.我尝试了很多解决方案,但没有一个对我有用。
Such kind of an error always occurs when using ES6 without babel being configured,在没有配置 babel 的情况下使用 ES6 时,总是会出现这种错误,
Can you try to run the tests with babel?你能尝试用 babel 运行测试吗?
Also, in your jest configuration, do your have testEnvironment set to "node", If yes, remove it.另外,在你的玩笑配置中,是否将 testEnvironment 设置为“节点”,如果是,请将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.