javascript - 错误 [ERR_REQUIRE_ESM]: ES 模块的 require()
问题描述
v13,终端显示此错误:
错误:const ms = require('parse-ms') // npm i parse-ms ^
错误 [ERR_REQUIRE_ESM]:ES 模块 C:\Users\DELL\OneDrive\Desktop\Discord Bot\node_modules\parse-ms\index.js 的 require() 来自 C:\Users\DELL\OneDrive\Desktop\Discord Bot\commands \Economy\beg.js 不支持。
代码:
const db = require('quick.db') // npm i quick.db
const ms = require('parse-ms') // npm i parse-ms
module.exports = {
commands: ['beg'], // You Can Keep Any Name
description: 'Beg For Money', // Optional
callback: (message, args) => {
const user = message.member
const random = (min, max) => {
return Math.floor(Math.random() * (max - min) ) + min
}
const timeout = 60000 // 1 Min In MiliSecond
const amount = Math.floor(Math.random() * 900) + 100 // Min Is 100 And Max Is 1000(100+900)
let names = [ // Find More Names In Description
'Sir Cole Jerkin',
'Kim Kardashian',
'Logan Paul',
'Mr.Clean',
'Ryan Gosling',
'Ariana Grande',
'Default Jonesy',
'Cardi B',
'Dwight Shrute',
'Jesus',
'Taylor Swift',
'Beyoncé',
'Bill Clinton',
'Bob Ross',
'The Rock:',
'The Rock',
'Mike Hoochie',
'Doot Skelly',
'Ayylien',
'Spoopy Skelo'
]
const name = Math.floor(Math.random() * names.length) // To Get Random Name
let options = [
'Success',
'Failed'
]
let begged = random(0, parseInt(options.length))
let final = options[begged]
const begtime = db.fetch(`beg-time_${user.id}`) // Keep `beg-time_${message.guild.id}_${user.id}` If You Want Different In All Servers
if(begtime !== null && timeout - (Date.now() - begtime) > 0) {
const timeleft = ms(timeout - (Date.now() - begtime))
const embed = new MessageEmbed()
.setAuthor(`${user.user.username} Begged`, user.user.displayAvatarURL({ dynamic: true }))
.setTimestamp()
.setColor('RANDOM')
.setDescription(`
Already Begged, Beg Again In **${timeleft.seconds} Seconds**
Default CoolDown Is **1 Minutes**
`)
message.channel.send({embeds: [embed]})
} else {
if(final === 'Success') {
let gave = [
'Donated',
'Gave'
]
const give = Math.floor(Math.random() * gave.length)
db.add(`money_${user.id}`, amount)
const embed1 = new MessageEmbed()
.setAuthor(`${user.user.username} Begged`, user.user.displayAvatarURL({ dynamic: true }))
.setTimestamp()
.setColor('RANDOM')
.setDescription(`
**${names[name]}**: ${gave[give]} **$${amount}** To <@${user.user.id}>
`)
message.channel.send({embeds: [embed1]})
db.set(`beg-time_${user.id}`, Date.now())
} else if(final === 'Failed') {
let notgave = [
`I Don't Have Money`,
`I Am Also Poor`,
`I Already Gave Money To Last Beggar`,
`Stop Begging`,
`Go Away`
]
const notgive = Math.floor(Math.random() * notgave.length)
const embed2 = new MessageEmbed()
.setAuthor(`${user.user.username} Begged`, user.user.displayAvatarURL({ dynamic: true }))
.setTimestamp()
.setColor('RANDOM')
.setDescription(`
**${names[name]}**: ${notgave[notgive]}
`)
message.channel.send({embeds: [embed2]})
db.set(`beg-time_${user.id}`, Date.now())
}
}
}
}```
解决方案
这个包的 V3.0 现在只支持使用 ES 模块,它们使用不同的语法进行导入。
您可以切换您当前的代码库以使用 ESM,或者另一个选项是将当前版本的 parse-ms 降级到 V2.1
参考这个: https ://github.com/sindresorhus/parse-ms/releases/tag/v3.0.0
推荐阅读
- java - 收到消息“这个元素下附有源代码或javadoc”不能有源代码导致程序崩溃?
- reactjs - 无法从不属于组件树的文件中导入 store redux?“初始化前无法访问存储”
- javascript - 无法让 jQuery 代码在 Wordpress 中工作,即使尝试 noConflict
- c# - 在多态类中调用的专门方法神经器
- sql - IF 语句给出空白单元格
- java - 如何在 fluentd 中解析多行 java 错误/异常堆栈跟踪输入(我应该通过 Kibana 看到相同的错误/异常堆栈跟踪)
- c# - 如何拒绝从 url 访问文件夹中的文件
- aes - 使用 CryptoJS 库在密文对象中可见的密钥和 IV
- python - 导入张量流时的 ImportError
- postgresql - 如何在 PostgreSQL 中查找数据库缺失的索引详细信息