title: react jest : Cannot use import statement outside a module
body: <p>I have been trying to implement tests with Jest for the first time and I have encountered the following error. I have also tried the recommended fixes found in other threads and have not fixed my problem.</p>
  <p>It seems that my &quot;import&quot; does not work at certain levels of my app.</p>
  <p>setupTests.js</p>
  <pre><code>import Enzyme from 'enzyme';
  import Adapter from 'enzyme-adapter-react-16';
  
  Enzyme.configure({
      adapter: new Adapter()
  });
  </code></pre>
  <p>babel.config.js</p>
  <pre><code>module.exports = {
      presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
    };
  
  
  </code></pre>
  <p>jest.config.json</p>
  <pre><code>{
      &quot;setupFiles&quot;: [
          &quot;raf/polyfill&quot;,
          &quot;&lt;rootDir&gt;/src/setupTests.js&quot;
      ]
  }
  
  </code></pre>
  <p>package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;front&quot;,
    &quot;version&quot;: &quot;0.1.0&quot;,
    &quot;private&quot;: true,
    &quot;dependencies&quot;: {
      &quot;@fortawesome/fontawesome-free&quot;: &quot;^5.15.1&quot;,
      &quot;@fortawesome/fontawesome-svg-core&quot;: &quot;^1.2.32&quot;,
      &quot;@fortawesome/free-solid-svg-icons&quot;: &quot;^5.15.1&quot;,
      &quot;@fortawesome/react-fontawesome&quot;: &quot;^0.1.12&quot;,
      &quot;@material-ui/core&quot;: &quot;^4.11.1&quot;,
      &quot;@material-ui/icons&quot;: &quot;^4.9.1&quot;,
      &quot;@material-ui/lab&quot;: &quot;^4.0.0-alpha.57&quot;,
      &quot;@testing-library/jest-dom&quot;: &quot;^5.11.6&quot;,
      &quot;@testing-library/user-event&quot;: &quot;^12.2.2&quot;,
      &quot;axios&quot;: &quot;^0.21.0&quot;,
      &quot;babel&quot;: &quot;^6.23.0&quot;,
      &quot;chart.js&quot;: &quot;^2.9.4&quot;,
      &quot;html-react-parser&quot;: &quot;^0.14.1&quot;,
      &quot;moment&quot;: &quot;^2.29.1&quot;,
      &quot;raf&quot;: &quot;^3.4.1&quot;,
      &quot;react&quot;: &quot;^17.0.1&quot;,
      &quot;react-chartjs-2&quot;: &quot;^2.11.1&quot;,
      &quot;react-dom&quot;: &quot;^17.0.1&quot;,
      &quot;react-redux&quot;: &quot;^7.2.2&quot;,
      &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
      &quot;react-scripts&quot;: &quot;4.0.0&quot;,
      &quot;react-test-renderer&quot;: &quot;^17.0.1&quot;,
      &quot;reactour&quot;: &quot;^1.18.0&quot;,
      &quot;recharts&quot;: &quot;^1.8.5&quot;,
      &quot;redux&quot;: &quot;^4.0.5&quot;,
      &quot;redux-devtools-extension&quot;: &quot;^2.13.8&quot;,
      &quot;redux-thunk&quot;: &quot;^2.3.0&quot;,
      &quot;styled-components&quot;: &quot;^4.4.1&quot;,
      &quot;universal-cookie&quot;: &quot;^4.0.4&quot;,
      &quot;victory&quot;: &quot;^35.3.5&quot;,
      &quot;web-vitals&quot;: &quot;^0.2.4&quot;
    },
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;react-scripts start&quot;,
      &quot;build&quot;: &quot;react-scripts build&quot;,
      &quot;test&quot;: &quot;react-scripts test&quot;,
      &quot;eject&quot;: &quot;react-scripts eject&quot;,
      &quot;testJ&quot;: &quot;jest --config=jest.config.json&quot;
    },
    &quot;eslintConfig&quot;: {
      &quot;extends&quot;: [
        &quot;react-app&quot;,
        &quot;react-app/jest&quot;
      ]
    },
    &quot;browserslist&quot;: {
      &quot;production&quot;: [
        &quot;&gt;0.2%&quot;,
        &quot;not dead&quot;,
        &quot;not op_mini all&quot;
      ],
      &quot;development&quot;: [
        &quot;last 1 chrome version&quot;,
        &quot;last 1 firefox version&quot;,
        &quot;last 1 safari version&quot;
      ]
    },
    &quot;devDependencies&quot;: {
      &quot;@testing-library/react&quot;: &quot;^11.2.2&quot;,
      &quot;enzyme&quot;: &quot;^3.11.0&quot;,
      &quot;enzyme-adapter-react-16&quot;: &quot;^1.15.5&quot;,
      &quot;jest&quot;: &quot;^26.6.3&quot;
    }
  }
  </code></pre>
  <p>Whenever I try to run my test suite I get the following error:</p>
  <pre><code> FAIL  src/tests/add.test.js
    ● 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. it's not plain JavaScript.
  
      By default, if Jest sees a Babel config, it will use that to transform your files, ignoring &quot;node_modules&quot;.
  
      Here's what you can do:
       • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
       • To have some of your &quot;node_modules&quot; files transformed, you can specify a custom &quot;transformIgnorePatterns&quot; in your config.
       • If you need a custom transformation specify a &quot;transform&quot; option in your config.
       • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the &quot;moduleNameMapper&quot; config option.
  
      You'll find more details and examples of these config options in the docs:
      https://jestjs.io/docs/en/configuration.html
  
      Details:
  
      /Users/jk/EpitechProjects/T-WEB-700/CountOfMoney_18/front/src/setupTests.js:6
      import Enzyme from 'enzyme';
      ^^^^^^
  
      SyntaxError: Cannot use import statement outside a module
  
        at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
  </code></pre>