GVKun编程网logo

如何在 Node.js UnhandledPromiseRejectionWarning 中找到未处理的承诺?(node未找到命令)

19

此处将为大家介绍关于如何在Node.jsUnhandledPromiseRejectionWarning中找到未处理的承诺?的详细内容,并且为您解答有关node未找到命令的相关问题,此外,我们还将为您

此处将为大家介绍关于如何在 Node.js UnhandledPromiseRejectionWarning 中找到未处理的承诺?的详细内容,并且为您解答有关node未找到命令的相关问题,此外,我们还将为您介绍关于(node:11224) UnhandledPromiseRejectionWarning: TypeError: this.getResolve is not a function、(node:274) UnhandledPromiseRejectionWarning: TypeError: db.all is not a function、(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...、discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义错误的属性“通道”的有用信息。

本文目录一览:

如何在 Node.js UnhandledPromiseRejectionWarning 中找到未处理的承诺?(node未找到命令)

如何在 Node.js UnhandledPromiseRejectionWarning 中找到未处理的承诺?(node未找到命令)

从版本 7 开始的 Node.js 具有用于处理 Promise 的 async/await 语法糖,现在在我的代码中经常出现以下警告:

(node:11057) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: Error: Can''t set headers after they are sent.(node:11057) 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.

不幸的是,没有提到 catch 丢失的行。有没有办法在不检查每个 try/catch 块的情况下找到它?

答案1

小编典典

监听unhandledRejection进程事件。

process.on(''unhandledRejection'', (reason, p) => {  console.log(''Unhandled Rejection at: Promise'', p, ''reason:'', reason);  // application specific logging, throwing an error, or other logic here});

(node:11224) UnhandledPromiseRejectionWarning: TypeError: this.getResolve is not a function

(node:11224) UnhandledPromiseRejectionWarning: TypeError: this.getResolve is not a function

来自/感谢:https://blog.csdn.net/qq_43379916/article/details/109190506

版本过高错误

比如我的webpack是3.6.0版本
而我的css-loader是5.0.0
这里就会出现这个错误
解决办法:
1,手动设置,然后采用npm install 重新下载
2,卸载重装

npm uninstall css-loader //卸载
npm install css-loader@3.0.0 --save-dev   //指定版本重装

 

(node:274) UnhandledPromiseRejectionWarning: TypeError: db.all is not a function

(node:274) UnhandledPromiseRejectionWarning: TypeError: db.all is not a function

如何解决(node:274) UnhandledPromiseRejectionWarning: TypeError: db.all is not a function?

这是我第一次在这里提问,所以请您尽快回答我,谢谢!无论如何,我正在使用 discord.js API 制作一个不和谐的机器人,但我遇到了一个问题。

代码:

if(message.content === PREFIX +"leaderboard"||"lb") {
      let money = db.all().filter(data => data.ID.startsWith(`money_`)).sort((a,b) => b.data - a.data);
        if (!money.length) {
            let noEmbed = new discord.MessageEmbed()
                .setAuthor(message.member.displayName,message.author.displayAvatarURL())
                .setColor("GREEN")
                .setFooter("nothing To See Here Yet!")
            return message.channel.send(noEmbed)
        }; 

错误:

UnhandledPromiseRejectionWarning: TypeError: db.all is not a function

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...

(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...

记录一次学习node.js犯的低级错误

这里遇到一个这样的问题

express连接mongoose时报错(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out after 30000 ms

连接数据库的代码

 1 const mongoose=require(''mongoose'')
 2 mongoose.connect(''mongodb://localhost:27017/express1'',{
 3   useNewUrlParser: true,
 4   useUnifiedTopology: true
 5 })
 6 
 7 
 8 const UserSchema=new mongoose.Schema({
 9   username:{type:String},
10   password:{type:String}
11 })
12 const User=mongoose.model(''User'',UserSchema)
13 module.exports = {
14   User
15 }

 

按照网上教程说不需用启动数据库直接可以连接,可是怎么也连接不上,一直报超时错误,网上查了一大堆的资料,有的说需要什么超级管理员权限,折腾了好久也没搞出来,而且网上这类似的问题很少,看来是没啥人遇到这样的问题,那估计就是我自己哪儿没写对吧,反复排查之后觉得可能还是需要本地启动mongod,然后尝试cmd里面启动mongod,再从新启动项目,终于成功了

 

discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义错误的属性“通道”

discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义错误的属性“通道”

如何解决discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义错误的属性“通道”?

错误:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property ''channel'' of undefined error

代码:

module.exports = {
    name: "ticket",aliases: [],permissions: ["SEND_MESSAGES"],description: "open a ticket!",async execute(message,args,cmd,client,discord) {
        const channel = await message.guild.channel.create(`ticket: ${message.author.tag}`);

        channel.setParent(''871385981465530409'');

        channel.updateOverwrite(message.guild.id,{
            SEND_MESSAGE: false,VIEW_CHANNEL: false,});
        channel.updateOverwrite(message.author,{
            SEND_MESSAGE: true,VIEW_CHANNEL: true,});

        const reactionMessage = await channel.send("Thank you for contacting support!");

        try {
            await reactionMessage.react("?");
            await reactionMessage.react("⛔");
        } catch (err) {
            channel.send("Error sending emojis!");
            throw err;
        }

        const collector = reactionMessage.createReactionCollector(
            (reaction,user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission("ADMINISTRATOR"),{ dispose: true }
        );

        collector.on("collect",(reaction,user) => {
            switch (reaction.emoji.name) {
                case "?":
                    channel.updateOverwrite(message.author,{ SEND_MESSAGES: false });
                    break;
                case "⛔":
                    channel.send("Deleting this channel in 5 seconds!");
                    setTimeout(() => channel.delete(),5000);
                    break;
            }
        });

        message.channel
            .send(`We will be right with you! ${channel}`)
            .then((msg) => {
                setTimeout(() => msg.delete(),7000);
                setTimeout(() => message.delete(),3000);
            })
            .catch((err) => {
                throw err;
            });
    },};

解决方法

在你的第一行,我可以看到两件事:

  1. 您的执行很可能不正确。确保参数的顺序正确。在您的 index.js、Message.js 或您执行此操作的任何文件中,参数为 message,args,cmd,client,discord
  2. 它不是Guild.channel,它实际上是带有“s”的Guild.channels
const channel = await message.guild.channels.create(`ticket: ${message.author.tag}`)

关于如何在 Node.js UnhandledPromiseRejectionWarning 中找到未处理的承诺?node未找到命令的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于(node:11224) UnhandledPromiseRejectionWarning: TypeError: this.getResolve is not a function、(node:274) UnhandledPromiseRejectionWarning: TypeError: db.all is not a function、(node:7584) UnhandledPromiseRejectionWarning: MongooseTimeoutError: Server selection timed out af...、discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义错误的属性“通道”的相关信息,请在本站寻找。

本文标签: