I have this issue when I'm trying to run the tests with this configuration: The text was updated successfully, but these errors were encountered: I am also seeing this issue. What am I missing? SyntaxError: Cannot use import statement outside a module Content Discovery initiative April 13 update: Related questions using a Review our technical responses for the 2023 Developer Survey, Importing in Node.js: error "Must use import to load ES Module", Problem with loading "ES module" when importing in node js, Cannot use import statement outside a module when importing "uuid", SyntaxError: Cannot use import statement outside a module (Type Script), "Cannot use import statement outside a module" (Cloud Convert API), web scraping SyntaxError: Cannot use import statement outside a module, import React, { useState } from 'react'; ^^^^^^ SyntaxError: Cannot use import statement outside a module, I get "SyntaxError: Cannot use import statement outside a module." Similar issue, but the module I'm having problems with has both es6 and cjs versions, and I'd rather use the cjs version rather than transpile the es6 one. But more to the point, it should just work without needing any configuration. Modified 4 days ago. I couldn't get rid of this SyntaxError: Cannot use import statement outside a module error no matter what I have tried and it got so frustrating. Find centralized, trusted content and collaborate around the technologies you use most. In the end, my jest.config.js looks mainly like this: P.S. This usually means that you are trying to import a file which Jest cannot parse, e.g. 565), Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI. difference between import and require. You can interpret individual files as CommonJS by using the .cjs extension. MUI5 not working with jest - SyntaxError: Cannot use import statement Considering that the main unit test frameworks Jasmine Jest etc don't handle this at all well it leaves me thinking that until there is better interop support the whole Node es6 situation seems half baked to me, but I'd love to be proven wrong.