How to resolve “Cannot use import statement outside a module” in jest

前端 未结 7 1715
庸人自扰
庸人自扰 2020-12-15 16:39

I have a React application (not using Create React App) built using TypeScript, Jest, Webpack, and Babel. When trying to run \"yarn jest\", I get the following error:

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 17:22

    Use Babel to transpile those JS Modules and you'll be able to write your tests with es6.

    Install Babel/preset-env

    npm i -D @babel/preset-env

    Create a babel configuration file with the preset

    //babel.config.js
    module.exports = {presets: ['@babel/preset-env']}
    

提交回复
热议问题