Code:
const { EmbedBuilder } = require("discord.js");
const got = require("got");
module.exports = {
name: "meme",
description: "Shows an image of a meme!",
run: async (client, message, args) => {
got("https://www.reddit.com/r/memes/random/.json").then(response => {
const [list] = JSON.parse(response.body);
const [post] = list.data.children;
const permalink = post.data.permalink;
const memeUrl = `https://reddit.com${post.data.permalink}`;
const memeImage = post.data.url;
const memeTitle = post.data.title;
const memeUpvotes = post.data.ups;
const memeNumComments = post.data.num_comments;
const memeEmbed = new EmbedBuilder()
.setTitle(`${memeTitle}`)
.setURL(`${memeUrl}`)
.setColor("Random")
.setImage(memeImage)
.setFooter({ text: `👍 ${memeUpvotes} | 💬 ${memeNumComments}` });
message.reply({ embeds: [memeEmbed] });
});
}
};
Error:
const got = require("got");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module
/app/node_modules/got/dist/source/index.js from /app/commands/Image/meme.js not supported.
I’m not too sure what this ESM is, I’ve never dealt with it before, therefore I don’t know what to do to fix this.
Kinda think it’s got to do something with the package itself, but like I said I’m clueless as I’ve never had this error before.
got is a native ESM and no longer provides a CommonJS export.
To use the latest version, you'll have to convert to ESM:
"type": "module" to your package.jsonrequire()s and module.exports with import and exportgotAnother option is to downgrade got to v11.8.3 as it's pretty stable:
You can run npm i got@11.8.3 in your console.