![](/img/trans.png)
[英]UnhandledPromiseRejectionWarning TypeError: Cannot read property 'property' of undefined
[英]UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined
我正在设置nodejs以便使用Jest javascript测试框架测试我的javascript代码。 我做错了什么?
package.json
文件 {
"name": "institute-jest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.4.0",
"jest": "^23.4.1",
"regenerator-runtime": "^0.12.0"
}
}
我在终端中运行npm test
后收到以下错误消息
(node:5088) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined
at Object.<anonymous> (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\chalk\index.js:72:75)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at _load_chalk (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\jest-cli\build\cli\index.js:67:43)
at Object.<anonymous> (C:\Users\Olakunle-PC\Desktop\nodejs\HomeStudyLabs\node_modules\jest\node_modules\jest-cli\build\cli\index.js:29:32)
(node:5088) 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:5088) [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.
如果出现未定义的错误,则需要确保为哪个变量抛出未定义的错误分配了一个值。
更多详细信息检查链接的详细信息以下代码可能有助于调试:
function test(t) {
if (t === undefined) {
console.log(t.tt)
}
return t;
}
我在下面做了以下操作来解决此问题
node_modules
目录。 package-lock.json
文件。 npm clear cache --force
。 npm install
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.