3

I creating a es6 javascript webpack project where i am using graphql-request node module. The project runs perfectly fine during runtime but when i run unit test using jest yarn test, i m running into

Cannot find module 'graphql-request' from 'xyx/abc.js'

    Require stack:
      xyx/abc.js
      tests/abc.test.js

at Resolver.resolveModule (node_modules/jestresolve/build/index.js:306:11)
      at Object.<anonymous> (src/abc.js:2:1)
      at Object.<anonymous> (tests/abc.test.js:1:44)


After a lot of google search, I was able to get it resolved by following the solution suggested here SO by adding the main entry to the package.json file of the graphql-request module in the node_modules/graphql-request. This hack would work in my local but not in other environments where the project would be built again. What would be the ideal fix be ?

graphql-request version 5.2.0 jest version 26.6.3 node 19.8.1

0 Answers0