Instead, ts-node might be the perfect replacement. If anyone is running into this issue with TypeScript, the key to solving it for me was changing. when your code or its dependencies use non-standar. The DatePicker component now will not respect locales. ex: jest.mock('rehype-raw/index.js', () => jest.fn()); I tried a lot of answers here, but nothing worked for me. So, you get the response you posted, where the JavaScript engine is saying it needs to know if the file is a Module type of JavaScript file. SyntaxError: Cannot use import statement outside a module. // package.json { "type": "module" } Option 2. I tried everything here and also tweaked my jest.config.js and babel.config.js and nothing worked. What positional accuracy (ie, arc seconds) is necessary to view Saturn, Uranus, beyond? By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Is there anybody out here solved this issue? Not the answer you're looking for? I have read a million stackoverflow and github issue threads. How a top-ranked engineering school reimagined CS curriculum (Ep. Babel unexpected token import when running mocha tests. Thank you Ben What a bloody life saver you have been today haha, MUI5 not working with jest - SyntaxError: Cannot use import statement outside a module, https://github.com/hutber/cannotusestatement, https://codesandbox.io/s/vigilant-bartik-bmz8x. So this jest configuration solved my issue: My issue was different in a way that jest would stumle on .js files from one of the dependencies in node_modules with SyntaxError: Cannot use import statement outside a module. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. Which was the first Sci-Fi story to predict obnoxious "robo calls"? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. I am using netbeans. SyntaxError: Cannot use import statement outside a module. Describe the bug When I add MDX documentation files into my Storybook and run Storyshots with Jest I'm getting SyntaxError: Cannot use import statement outside a module for each of loaded MDX. So, you can't compare an app and a module. Not the answer you're looking for? This used to work fine, but after updating Jest the tests now cease to run. Looking for job perks? This happens e.g. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".