Search code examples
reactjsjestjsbabeljscreate-react-app

Cannot find module - Error when running tests on react project


When i run yarn test locally on my React project i get this error (project is created with Create react app):

Cannot find module <project_directory>node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/interopRequireDefault

Everything was normal and after adding react-responsive package, my tests started failing like this.
Even though they show that they fail, when i choose to run only failed tests, they don't run again. It's like they failed in their own way but not concerning the test process.

On the side note, when my tests run on CI/CD pipeline, they work with no problem.


Solution

  • After taking into consideration that CI/CD pipeline test run succeeds, i got to thinking that it could have to do something with my local environment.

    Solution is to first clear cache in tests and than run tests again:

    yarn test --clearCache
    

    And that run

    yarn test
    

    NPM variant:

    npm test -- --clearCache
    

    And everything works fine now.

    I found out on this issue that regards on a similar error but for a different module.
    This answer gave me a solution

    Issue in on create react app repo