Inside these files I am using es6 modules. We could use a preset, like babel-jest, or we can just compile jest : Cannot use import statement outside a module The yarn build command produces those files (there is something wrong somewhere, why does the build produces index.js when there is the index.mjs?) "SyntaxError: Cannot use import statement outside a module" when ... So, for example when you are using lodash, you want to use import cloneDeep from 'lodash-es/cloneDeep'; instead of import { cloneDeep } from 'lodash-es';. So I guess if the module were called babel-jest-hooray then the "path to transformer" would be the string "babel-jest-hooray". [Nodejs, Typescript] Lỗi: Cannot use import statement outside a module SyntaxError: Cannot use import statement outside a module while using ... How to resolve "Cannot use import statement outside a module" in angular. By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules". Answer. I have no idea what this exactly means, but my best guess is that since we had to install the babel-jest module, "babel-jest" is a path to that module. Specifically testing a component that imports from @sapper/app. It causes the following error: Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6 Common Cases of "SyntaxError: Cannot use import statement outside a module" This can happen in different cases depending on whether you're working with JavaScript on the server-side with Node.js, or client-side in the browser. 解决方法 1.没有用babel转换es6语法. I have this issue when I'm trying to run the tests with this configuration: jest.config.js. Jest Autoconfiguration: [Error] SyntaxError: Cannot use import ... I have no idea what this exactly means, but my best guess is that since we had to install the babel-jest module, "babel-jest" is a path to that module. SyntaxError: Cannot use import statement outside a module. SyntaxError: Cannot use import statement outside a module This is one of the most common issue if you are trying to use ES6 features in your JavaScript project. In my node.js (with typescript) project, I try to use crypto-random-string package for generating random string value..