reactjsjestjsbabel-jest

Jest Unit tests are failing


Getting below error while running unit tests for react app. I am using jest to run it.

I didn't have the file mentioned in below error in my code base.

I searched many places but didn't found solution. Can anyone help me with this?

` Test suite failed to run

Cannot find module 'node:stream' from 'index.js'

However, Jest was able to find:
    './Utils.js'
    './Utils.js.map'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

However, Jest was able to find:
    './utils.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

However, Jest was able to find:
    './createSerializer.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
  at Object.<anonymous> (node_modules/parse5-parser-stream/dist/cjs/index.js:4:23)

`

I searched in many forums and tries some options but didn't worked.


Solution

  • I ran into this issue the other day too. Turned out to be a dependency of Enzyme that was causing the issue. I had to pin "cheerio" to version "cheerio": "1.0.0-rc.12". The latest version "1.0.0-rc.3" was installing parse5-parser-stream which is causing the node:stream error. Hope this helps!