Asked 1 month ago by AsteroidPilot689
Jest Upgrade Error: ENOENT 'node:stream' Not Found When Upgrading from Jest 23 to 26
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by AsteroidPilot689
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
We are upgrading from Jest 23 to 26 but encounter the following error when running tests:
BASHENOENT: no such file or directory, open 'node:stream' at Runtime.readFile (node_modules/jest-runner/node_modules/jest-runtime/build/index.js:1987:21) at Object.<anonymous> (node_modules/parse5-parser-stream/dist/cjs/index.js:4:23)
Despite installing the stream package, the error persists and it seems that jest-runtime isn’t finding the package in node_modules. Below are relevant configuration snippets:
package.json
JSON{ "devDependencies": { "babel-jest": "^26.0.0", "chai": "^4.1.2", "chai-enzyme": "^1.0.0-beta.1", "chai-jest-mocks": "^1.2.4", "compression-webpack-plugin": "^1.1.11", "copy-webpack-plugin": "^4.6.0", "enzyme": "^3.4.2", "enzyme-adapter-react-16": "^1.2.0", "eslint": "^4.19.1", "eslint-loader": "^4.0.2", "eslint-plugin-import": "^2.14.0", "eslint-plugin-jsx-a11y": "^6.1.1", "eslint-plugin-react": "^7.10.0", "eslint-plugin-react-hooks": "^1.6.1", "eslint-watch": "^4.0.2", "expose-loader": "^0.7.5", "extract-loader": "^3.0.0", "file-loader": "^2.0.0", "filewatcher-webpack-plugin": "^1.2.0", "gulp-nuget-restore": "^0.4.0", "jest": "^26.0.0", "jsx-loader": "^0.13.2", "mini-css-extract-plugin": "^0.4.4", "node-sass": "^5.0.0", "postcss-flexbugs-fixes": "^4.1.0", "postcss-preset-env": "^6.3.0", "redux-mock-store": "^1.5.4", "replace-in-file-webpack-plugin": "^1.0.6", "stream": "0.0.3", "uglifyjs-webpack-plugin": "^1.3.0", "webpack": "^4.20.2", "webpack-bundle-analyzer": "^2.13.1", "webpack-cli": "^3.1.1", "webpack-merge": "^4.1.4" } }
babelrc
JSON{ "presets": [ "@babel/react", "@babel/env" ], "plugins": [ "@babel/plugin-proposal-class-properties" ] }
Edit 1:
After resolving the above with hints from the answer at Jest Unit tests are failing, more tests now show:
TypeError: Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a Symbol.iterator method.
Any insights into why jest-runtime might not be resolving the built-in module correctly and how to proceed are appreciated.
Comments 0
•Answers 2
•Views 53
Answer by TychoAI Agent • 1 month ago
This error arises because one of your dependencies (parse5-parser-stream) is importing a Node core module using the new "node:" URL scheme (i.e. "node:stream"). This syntax is supported starting in Node v16, and Jest’s runtime (or your Node environment running Jest) is treating it as a request for a file instead of a built‐in module.
You have two main options:
Make sure you’re using Node v16 or later. This way the "node:" syntax is natively supported, and Jest will correctly resolve core modules. You can check your Node version by running:
BASHnode --version
If you’re on an older version, consider upgrading to avoid compatibility issues.
If upgrading Node isn’t feasible at the moment, you can add a mapping in your Jest configuration that remaps imports starting with "node:" to the same module without the prefix. In your Jest config (commonly in package.json under "jest" or in a separate jest.config.js file), add the following:
JS// jest.config.js module.exports = { moduleNameMapper: { '^node:(.+)$': '$1' }, // ...other configuration options };
This tells Jest to replace any import that starts with "node:" with the plain module name (e.g. "stream"), allowing Node to resolve it as a built-in module.
After resolving the "node:stream" issue, you mentioned another error regarding an "Invalid attempt to spread non-iterable instance." That error typically occurs when code is attempting to use the spread operator on an object that isn’t iterable (i.e. it lacks a Symbol.iterator). This might be a separate issue related to updated transforms or runtime code—make sure that your Babel configuration is correct and that any code using spread syntax is indeed applied to arrays or iterable objects.
Implementing one of the above fixes should resolve the ENOENT error about "node:stream" during your Jest run.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by SolarRover197 • 1 month ago
found answer for original question with below
and and the follow up error with change to bablrc as advised in answers here -
No comments yet.
No comments yet.