Javascript 未处理的PromisejectionWarning:TypeError:无法读取属性';关闭';未定义的

Javascript 未处理的PromisejectionWarning:TypeError:无法读取属性';关闭';未定义的,javascript,node.js,npm,jestjs,Javascript,Node.js,Npm,Jestjs,我正在设置nodejs,以便使用jest-javascript测试框架测试我的javascript代码。我做错了什么 package.json文件 在终端中运行npm测试后,我收到以下错误消息 (node:5088) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined at Object.<anonymous> (C:\Users\Olakunle-PC\

我正在设置nodejs,以便使用jest-javascript测试框架测试我的javascript代码。我做错了什么

package.json
文件 在终端中运行
npm测试后,我收到以下错误消息

(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.
(节点:5088)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“close”
反对。(C:\Users\Olakunle PC\Desktop\nodejs\homestudylab\node\u modules\jest\node\u modules\chalk\index.js:72:75)
at模块编译(内部/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:700:10)
在Module.load(内部/modules/cjs/loader.js:599:32)
在tryModuleLoad(内部/modules/cjs/loader.js:538:12)
at Function.Module._load(内部/modules/cjs/loader.js:530:3)
at Module.require(内部/modules/cjs/loader.js:637:17)
根据需要(内部/modules/cjs/helpers.js:22:18)
在\u load\u chalk(C:\Users\Olakunle PC\Desktop\nodejs\homestudylab\node\u modules\jest\node\u modules\jest cli\build\cli\index.js:67:43)
反对。(C:\Users\Olakunle PC\Desktop\nodejs\homestudylab\node\u modules\jest\node\u modules\jest cli\build\cli\index.js:29:32)
(节点:5088)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:1)
(节点:5088)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的拒绝承诺将终止
具有非零退出代码的Node.js进程。

如果出现未定义的错误,则需要确保为抛出未定义错误的变量分配了一个值

更多详细信息检查链接 以下代码可能有助于调试:

function test(t) {     
  if (t === undefined) { 
        console.log(t.tt)
  }
  return t;    
}

如果您得到未定义的错误,您需要确保为抛出未定义错误的变量分配了一个值

更多详细信息检查链接 以下代码可能有助于调试:

function test(t) {     
  if (t === undefined) { 
        console.log(t.tt)
  }
  return t;    
}

为了解决此问题,我执行了以下操作

  • 已删除
    节点\u模块
    目录
  • 已删除
    包锁.json
    文件
  • 运行
    npm清除缓存--force
  • 然后运行
    npm安装

我执行了以下操作来解决此问题

  • 已删除
    节点\u模块
    目录
  • 已删除
    包锁.json
    文件
  • 运行
    npm清除缓存--force
  • 然后运行
    npm安装

能否显示index.js文件。我想问题出在这个文件上。你能显示你的index.js文件吗。我认为问题在于,提问者并不是在问如何管理未定义或空值。他的问题是关于jest框架不是通过npm测试启动的。提问者不是问如何管理未定义或空值。他的问题是关于jest框架不是通过npm测试启动的。