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

前端 未结 7 1721
庸人自扰
庸人自扰 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:23

    Solution: my named imports were coming from index.js files and I believe ts-jest needed them as index.ts files (I'm using Typescript). If anyone else runs into this error, couldn't hurt to check if you derped your file extensions.

    I wasted a lot of time on this, unfortunately, but I learned a lot about webpack configurations and Babel.

提交回复
热议问题