title: Jest cannot find module
body: <p>Hi I am trying to use Jest, but it keeps giving an error of cannot find module. I am not sure if this has to do with the paths of the files. All the files below are located out of my src folder. I have my file set up below.</p>
  <p>jest.config.js file:</p>
  <pre><code>module.exports = {
      &quot;collectCoverage&quot;: true,
      &quot;coverageDirectory&quot;: &quot;coverage&quot;,
      &quot;verbose&quot;: true,
      &quot;roots&quot;: [
          &quot;./__tests__&quot;
      ],
      &quot;transform&quot;: {
          &quot;^.+\\.js?$&quot;: &quot;babel-jest&quot;
      },
      &quot;coverageThreshold&quot;: {
          &quot;global&quot;: {
              &quot;branches&quot;: 78,
              &quot;functions&quot;: 90,
              &quot;lines&quot;: 90,
              &quot;statements&quot;: 90
          }
      },
      &quot;setupFiles&quot;: [
          &quot;./setupTest&quot;
      ],
      &quot;moduleDirectories&quot;: [&quot;node_modules&quot;, &quot;src&quot;]
  }
  </code></pre>
  <p>my test file located in __ test __:</p>
  <pre><code>import React from 'react';
  import { shallow, mount } from 'enzyme';
  import Routes, { OrderScreen, ShippingScreen, HomeScreen } from ../../src/App';
  import {
      MemoryRouter
  } from 'react-router'
  import { Route } from 'react-router-dom';
  
  let pathMap = {};
  describe('App', () =&gt; {
      beforeAll(() =&gt; {
          const component = shallow(&lt;Routes /&gt;);
          pathMap = component.find(Route).reduce((pathMap, route) =&gt; {
              const routeProps = route.props();
              pathMap[routeProps.path] = routeProps.component;
              return pathMap;
          }, {});
          console.log(pathMap)
      })
      it('should show Home component for / router (getting array of routes)', () =&gt; {
  
          expect(pathMap['/']).toBe(HomeScreen);
      })
      it('should show News Feed component for /news router', () =&gt; {
          expect(pathMap['/order/:id']).toBe(OrderScreen);
      })
      it('should show News Feed component techdomain for /news router', () =&gt; {
          expect(pathMap['/shipping']).toBe(ShippingScreen);
      })
      it('should show No match component for route not defined', () =&gt; {
          expect(pathMap['/search/:keyword/page/:pageNumber']).toBe(HomeScreen);
      })
  
  })
  </code></pre>
  <p>package jason</p>
  <pre><code>{
      &quot;name&quot;: &quot;frontend&quot;,
      &quot;proxy&quot;: &quot;http://127.0.0.1:5000&quot;,
      &quot;version&quot;: &quot;0.1.0&quot;,
      &quot;private&quot;: true,
      &quot;dependencies&quot;: {
          &quot;@babel/plugin-syntax-dynamic-import&quot;: &quot;^7.8.3&quot;,
          &quot;@babel/plugin-transform-react-jsx&quot;: &quot;^7.12.17&quot;,
          &quot;@testing-library/user-event&quot;: &quot;^12.1.10&quot;,
          &quot;axios&quot;: &quot;^0.21.1&quot;,
          &quot;babel-plugin-transform-class-properties&quot;: &quot;^6.24.1&quot;,
          &quot;react&quot;: &quot;^17.0.1&quot;,
          &quot;react-bootstrap&quot;: &quot;^1.4.3&quot;,
          &quot;react-redux&quot;: &quot;^7.2.2&quot;,
          &quot;react-router-bootstrap&quot;: &quot;^0.25.0&quot;,
          &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
          &quot;react-scripts&quot;: &quot;4.0.1&quot;,
          &quot;react-side-effect&quot;: &quot;^2.1.1&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;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:t&quot;: &quot;react-scripts test&quot;,
          &quot;eject&quot;: &quot;react-scripts eject&quot;,
          &quot;test&quot;: &quot;jest&quot;,
          &quot;test:cover&quot;: &quot;jest --coverage&quot;,
          &quot;open:coverage&quot;: &quot;open ./coverage/lcov-report/index.html&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;@babel/core&quot;: &quot;^7.13.8&quot;,
          &quot;@babel/plugin-proposal-class-properties&quot;: &quot;^7.13.0&quot;,
          &quot;@babel/preset-env&quot;: &quot;^7.13.8&quot;,
          &quot;@babel/preset-react&quot;: &quot;^7.12.13&quot;,
          &quot;@testing-library/jest-dom&quot;: &quot;^5.11.9&quot;,
          &quot;@testing-library/react&quot;: &quot;^11.2.5&quot;,
          &quot;babel-jest&quot;: &quot;^26.6.3&quot;,
          &quot;enzyme&quot;: &quot;^3.11.0&quot;,
          &quot;enzyme-adapter-react-16&quot;: &quot;^1.15.6&quot;,
          &quot;jest&quot;: &quot;^26.6.3&quot;,
          &quot;jest-enzyme&quot;: &quot;^7.1.2&quot;,
          &quot;react-dom&quot;: &quot;^17.0.1&quot;
      }
  }
  </code></pre>
  <p>babel.config.js</p>
  <pre><code>module.exports = {
      presets: [
          ['@babel/preset-env', { targets: { node: 'current' } }],
          ['@babel/preset-react', { targets: { node: 'current' } }] // add this
      ]
  };
  </code></pre>
  <p>Everything seems fine I've been following a tutorial but I cannot get over the error cannot find module it happens in my test file at this line</p>
  <pre><code>&gt; 4 | import App, { App as AppComponent } from '../../src/App';
  </code></pre>
  <p>Does this have to do something with paths that need to be fixed? everything is located outside of my src folder. My main file App.js which I am trying to test is within my src folder.</p>