TypeError: Cannot read property 'close' of undefined
See original GitHub issueBug Report
Attempting to run Jest (via yarn run test:ci
) in container as part of Jenkins pipeline. Works flawlessly on local machine, but fails randomly on Jenkins. About half of identical builds are coming back with the following error.
$ jest --coverage --ci
(node:45) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined
at Object.<anonymous> (/var/lib/jenkins/workspace/portal-ui-gerrit-build-develop/node_modules/chalk/index.js:72:75)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at _load_chalk (/var/lib/jenkins/workspace/portal-ui-gerrit-build-develop/node_modules/jest-cli/build/cli/index.js:67:42)
at Object.<anonymous> (/var/lib/jenkins/workspace/portal-ui-gerrit-build-develop/node_modules/jest-cli/build/cli/index.js:23:32)
(node:45) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:45) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Jest configuration
"jest": {
"preset": "jest-preset-angular",
"roots": [
"<rootDir>/src/"
],
"setupTestFrameworkScriptFile": "<rootDir>/src/setup-jest.ts",
"testResultsProcessor": "jest-junit"
},
"jest-junit": {
"suiteName": "Jest Unit Tests",
"output": "./reports/jest.xml",
"classNameTemplate": "{classname}-{title}",
"titleTemplate": "{classname}-{title}",
"ancestorSeparator": " › ",
"usePathForSuiteName": "true"
},
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (2 by maintainers)
Top Results From Across the Web
SOLVED: TypeError: Cannot read property 'close' of undefined
Hi Everyone, Hope you are enjoying the course! If anyone is experiencing the below issue like this: TypeError: Cannot read property 'close' ......
Read more >Uncaught TypeError: Cannot read property 'close' of undefined
You have to click Open "myWindow" button before clicking the other one, because that is when the variable myWindow gets initial value.
Read more >Uncaught TypeError: Cannot read property 'close' of undefined
Hi,. I am using the package v19.1.0.58 with <script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>. I have two new issues using Diagram (see ...
Read more >Cannot read property 'close' of undefined · Issue #536 · doczjs ...
I've noticed that the problem appears when using docz with react-scripts and the reason is a different version of 'ansi-styles'. Currently, you can...
Read more >Cannot Read Property of Undefined in JavaScript - Rollbar
The TypeError: Cannot read property of undefined is one of the most common type errors in JavaScript. It occurs when a property is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had this issue because another module was installing
ansi-styles
that was an older version at the root of the projectsnode_modules
. To fix ran the following command and everything started working again for me:npm i --save-dev chalk@2.4.2 ansi-styles@3.2.1
It’s not an issue with chalk, it’s because you have left dangling async code on a sync test (or you haven’t waited for all stuff on an async test). Line 72 of
chalk/index.js
contains a reference to arequire
result. Jest picks it and inlines therequire
call, for performance reasons, resulting in:However, your test has already finished, meaning the environment has been disposed, and any further call to
require
will result in a failure. Possible mitigations for this are in my comment above; the fact that does not fail locally is probably a race condition.