skip to Main Content

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.

2

Answers


  1. 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!

    Login or Signup to reply.
  2. I ran into the same issue, as @jlogue mentioned, but I had it as a transitive dependency – Added it as a top-level dependency, with version "1.0.0-rc.12" and it worked like a charm.
    Great catch!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search