Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest can't resolve import with @ (at) character

I have a problem. When I run Jest tests it can't resolve my imports with at (@) signs. I have an error:

 FAIL  src/App.test.js
  ● Test suite failed to run

    Cannot find module '@/helpers/configureStore' from 'App.js'

How do I resolve this error?

like image 219
Qback Avatar asked Oct 18 '25 05:10

Qback


1 Answers

I found the solution in this post. So according to the jest docs we should go to our package.json file, and make sure our config contains something like:

{
  "jest": {
    "moduleNameMapper": {
       "@/(.*)$": "<rootDir>/src/$1"
    }
  }
}

"@/(.*)$": "<rootDir>/src/$1" that's a cool regex which will resolve our @/helpers/configureStore to src/helpers/configureStore.

Also remember to quit from jest interactive mode (with q key) and run it again to see changes.

like image 139
Qback Avatar answered Oct 20 '25 19:10

Qback



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!