node报错,找不到原因

查看:155
本文介绍了node报错,找不到原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

代码调试了n遍,都正常,node为什么会报如下错误:

(node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property '1' of null
(node:18) 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.

这是代码,调试的一切正常

...
case 49:
    let title = content.match(/<title>(.*)<\/title>/)[1];
    let des = content.match(/<des>(.*)<\/des>/)[1];
    let link = content.match(/<url>(.*)<\/url>/)[1];

    content = `APP:` +
        `标题:${title}\n` +  //这里的变量都显示正常
        `描述:${des}\n` +    //这里的变量都显示正常
        `链接:${link}`;      //这里的变量都显示正常
    break;
...

解决方案

看报错信息很明显

let title = content.match(/<title>(.*)<\/title>/)[1];
    let des = content.match(/<des>(.*)<\/des>/)[1];
    let link = content.match(/<url>(.*)<\/url>/)[1];
    

这里有东西没有匹配到,所以null[1]出错

这篇关于node报错,找不到原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆