简体   繁体   English

错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:package.json 中没有定义“exports”main

[英]Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json

How can I fix 'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json'?如何修复“错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]: 在 package.json 中没有定义“导出”主要内容? How can I fix this error?我该如何解决这个错误? I've been trying for awhile and had help and we can't figure it out.我已经尝试了一段时间并得到了帮助,但我们无法弄清楚。 I dont understand the issue at all and it's starting to confuse me the more I think about it.我根本不明白这个问题,而且我越想越困惑。

JavaScript Code: JavaScript 代码:

const { Client, Intents, Collection } = require('discord.js')
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')
const Discord = require('discord.js')

const fs = require('fs')
const intents = new Discord.Intents(32767);
const client = new Discord.Client({ intents });

const config = require('./Data/config.json')

const versionNumber = "V1.0.0"

client.once("ready", () => {
    console.log('-------------------------------------------');
    console.log(`| Successfully logged in as Logic RP#7590 |`);
    console.log('-------------------------------------------');

    const commands = []
    const commands_information = new Collection();
    const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))

    for (const file of commandFiles) {
        const command = require(`./commands/${file}`)
        console.log(`Command loaded: ${command.data.name}`)
        commands.push(command.data.toJSON())
        commands_information.set(command.data.name, command);
    }

    const rest = new REST({ version: '9' }).setToken(config.token);

    (async () => {
        try {
            console.log('Started refreshing application (/) commands.');
            await rest.put(
                Routes.applicationGuildCommands(config.clientID, config.guildID),
                { body: commands },
            );
            console.log('Successfully reloaded application (/) commands.');
        } catch (error) {
            console.error(error);
        }
    })();

    client.on('interactionCreate', async interaction => {
        if (!interaction.isCommand()) return;

        const { commandName } = interaction;

        if (!commands_information.has(commandName)) return;

        try {
            await commands_information.get(commandName).execute(client, interaction, config);
        } catch (error) {
            console.error(error);
            await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
        }
    })
})

client.on("guildMemberAdd", async (member) => {
    let members = client.guilds.cache.reduce((a, g) => a + g.memberCount, 0);
    console.log(`${member.user.tag} has joined Logic RP`);
    console.log('-------------------------------------------');
    const embed = new Discord.MessageEmbed()
        .setTitle(`Welcome to the ${member.guild.name} Discord server!`)
        .setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
        .setColor('GREEN')
        .addFields(
            { 
                name: "✅ Have fun!",
                value: "The most important thing for us is that YOU have fun! You can chat with others in <#898349995315576883> and have all the fun that you want or talk to the community.", 
                inline: false 
            },
            { 
                name: "📘 Check out our rules!",
                value: "If you'd like to stay in this server, we ask that you read and follow all of our rules in <#898346754926338048>. This is important.",
                inline: false 
            },
            { 
                name: "🔔 Get your roles!", 
                value: "If you'd like to get notified for certain events or things related to this server, please check out <#898350339571462155> and get the roles that you want.", 
                inline: false 
            },
        )
        .setFooter(`Logic RP | ${versionNumber} - Member #${members}`)
        .setTimestamp()
    
    client.channels.cache.get('898346590245363772').send({embeds: [embed]});
})

client.login(config.token);

//npm run dev

JSON File: JSON 文件:

{
  "name": "logic-rp-discord-bot",
  "version": "1.0.0",
  "description": "Logic RP Discord Bot",
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon -e js"
  },
  "author": "killrebeest#1001",
  "license": "ISC",
  "dependencies": {
    "@discordjs/builders": "^0.6.0",
    "@discordjs/rest": "^0.1.0-canary.0",
    "discord-api-types": "^0.23.1",
    "discord.js": "^13.3.0-dev.1634342688.38cc89e",
    "lodash": "^4.17.21",
    "path": "^0.12.7",
    "wokcommands": "^1.5.3"
  },
  "keywords": []
}

Whois.js Code: Whois.js 代码:

const SlashCommandBuilder = require('@discordjs/builders')
const InteractionResponseType = require('discord-api-types')
const Discord = require('discord.js')

module.exports = {
    data: new SlashCommandBuilder()
        .setName('whois')
        .setDescription(`Information about a specified user.`),
    async execute(client, interaction, config) {
        const { guild, channel } = interaction

        const user = interaction.mentions.users.first() || interaction.member.user
        const member = guild.members.cache.get(user.id)

        console.log(member)

        const embed = new Discord.MessageEmbed()
            .setTitle(`Who is ${interaction}?`)
            .addFields(
                {
                    name: "User Tag:",
                    value: user.tag
                },
                {
                    name: "Is Bot:",
                    value: user.bot
                },
                {
                    name: "Nickname:",
                    value: member.nickname || 'None'
                },
                {
                    name: "Joined Server:",
                    value: new Date(member.joinedTimeStamp).toLocaleDateString()
                },
                {
                    name: "Joined Discord:",
                    value: new Date(user.createdTimeStamp).toLocaleDateString()
                },
                {
                    name: "Roles",
                    value: member.roles.cache.size - 1
                }
            )
            .setColor('AQUA')
            .setThumbnail(interaction.user.displayAvatarURL({ dynamic: true }))
        interaction.reply({ embeds: [embed] })
}}

Error Logs:错误日志:

node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\sjim4\Desktop\Logic RP Discord Bot\node_modules\discord-api-types\package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\sjim4\Desktop\Logic RP Discord Bot\src\commands\whois.js:2:33) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

Any help would be much appreciated.任何帮助将非常感激。

From the discord-api-types README:来自discord-api-types README:

You can only import this module by specifying the API version you want to target.您只能通过指定要定位的 API 版本来导入此模块。 Append /v* to the import path, where the * represents the API version.将 /v* 附加到导入路径,其中 * 表示 API 版本。

Thus, your require statement should look something like this:因此,您的 require 语句应如下所示:

const { InteractionResponseType } = require('discord-api-types/v9');

Use the latest discord-api-types, remove the old version from package.json and run npm i discord-api-types again.使用最新的 discord-api-types,从 package.json 中删除旧版本并再次运行 npm i discord-api-types。 That worked for me.那对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:@babel/helper-compilation-targets/package.json 中没有解决“导出”主要问题 - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in@babel/helper-compilation-targets/package.json FIREBASE 函数(错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:未定义“导出”主要内容) - FIREBASE FUNCTIONS (Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined) 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:包子路径 &#39;./src/util/Constants.js&#39; 不是由 \\&quot;exports\\&quot; 定义的 - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './src/util/Constants.js' is not defined by \"exports\" 我在使用 Graphql-upload [ERR_PACKAGE_PATH_NOT_EXPORTED] 上传图像时遇到问题:没有定义“出口”主要 - I am facing issue while uploading image using Graphql-upload [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]: 包子路径 &#39;./dist/types/single-spa-layout-interface&#39; 未由 &quot;exports&quot; 定义 - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/types/single-spa-layout-interface' is not defined by "exports" in 应用程序构建:错误 [ERR_PACKAGE_PATH_NOT_EXPORTED] - Application build: Error [ERR_PACKAGE_PATH_NOT_EXPORTED] 纱线开始不工作 | 错误“ERR_PACKAGE_PATH_NOT_EXPORTED” - Yarn start not working | error `ERR_PACKAGE_PATH_NOT_EXPORTED' 错误:在 graphql-upload/package.json 中没有定义主要的“导出” - Error: No "exports" main defined in graphql-upload/package.json 如何解决包子路径 &#39;./package.json&#39; is not defined by &quot;exports&quot; 错误 - How to resolve Package subpath './package.json' is not defined by "exports" error 错误:在 /app/node_modules/chart.js/package.json 中没有使用 nextjs 和 chartjs 定义“导出”主要内容 - Error: No "exports" main defined in /app/node_modules/chart.js/package.json with nextjs and chartjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM