Unable run `bit test` with jest error `import outside module`

Hi all,

I wonder how to setup the testing with Jest with below Bit component settings:

  • component with create-react-component (using TypeScript template)
  • Bit setup
"bit": {
  "env": {
    "compiler": "bit.envs/compilers/react-typescript@3.1.44",
    "tester": "bit.envs/testers/jest@22.4.3"
  "componentsDefaultDirectory": "components/{name}",
  "packageManager": "npm",
  "overrides": {
    "*": {
      "devDependencies": {
        "@types/node": "+",
        "@types/jest": "^25.1.2"
      "peerDependencies" : {
        "react-dom": "+"

The component has a very simple testing case with required some modules:

\\ CountButton.spec.ts
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import CountButton from "./CountButton";

I can run the test well at local with yarn test but when try to run bit test count-button having error:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from "react";
    SyntaxError: Cannot use import statement outside a module

I had tried a few solutions but it does not work with bit test. Please help to give me some advises.

Thank you.

1 Like

Any update on this? I’m having the same issue as well.

UPDATE: I was able to fix the import outside module error by overriding the tsconfig and switching the “module” type to “commonjs”, but now I get an error due to css modules in my files.