【问题标题】:Replacing main.js with index.js, Error: ENOENT?用 index.js 替换 main.js,错误:ENOENT?
【发布时间】:2023-03-19 07:43:01
【问题描述】:

我很困惑为什么这个机器人现在可以运行,我认为这是因为我没有“index.js”我使用“main.js”我怎样才能从“main.js”切换到“index.js”?

我将添加所有可能帮助您发现错误的主要代码:D

这是“main.js”中的代码:

const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ disableMentions: 'everyone', partials: 
['MESSAGE', 'CHANNEL', 'REACTION'], ws: { intents: Intents.ALL } });


client.commands = new Collection();
client.aliases = new Collection();

['command', 'event'].forEach(handler => {
    require(`./handlers/${handler}`)(client);
});


client.login(process.env.BOT_TOKEN);

错误:

internal/fs/utils.js:269
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/home/runner/DwaCraft-Ticket-bot/index.js'
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at Object.<anonymous> (/run_dir/interp.js:195:19)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/runner/DwaCraft-Ticket-bot/index.js'
}
repl process died unexpectedly: exit status 1
 

包.json:

{
    "name": "ticket-bot",
    "version": "1.0.0",
    "description": "A simple ticket bot",
    "main": "main.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node main.js"
    },
    "author": "hamoodi",
    "license": "ISC",
    "dependencies": {
        "better": "^0.1.0",
        "cpu-stat": "^2.0.1",
        "discord.js": "^12.5.3",
        "dotenv": "^8.6.0",
        "express": "^4.17.1",
        "moment": "^2.29.1",
        "os": "^0.1.2",
        "sourcebin_js": "0.0.3-ignore"
    }
}

文件:

https://i.stack.imgur.com/FptiD.png

【问题讨论】:

  • 将json包中的main属性改为main.js
  • 它是:“main”:“main.js”,
  • 能否请您添加包json以及如何运行您的项目?
  • 当然,一秒钟。
  • 给你,添加。

标签: javascript node.js discord.js


【解决方案1】:

如下链接所说,您可以创建一个 .replit 文件,并在其中放入

run="节点[文件].js"

并将 [file] 替换为 main。

https://replit.com/talk/ask/Is-it-possible-to-changedeleted-indexjs/43264

【讨论】:

    【解决方案2】:

    将名称文件从main.js 更改为index.js in "scripts" => "start" in package.json 文件并点击npm start。记得从 main.js 文件所在的folder 运行script,并重命名文件

    {
        "name": "ticket-bot",
        "version": "1.0.0",
        "description": "A simple ticket bot",
        "main": "main.js",
        "scripts": {
            "test": "echo \"Error: no test specified\" && exit 1",
            "start": "node index.js"
        },
        "author": "hamoodi",
        "license": "ISC",
        "dependencies": {
            "better": "^0.1.0",
            "cpu-stat": "^2.0.1",
            "discord.js": "^12.5.3",
            "dotenv": "^8.6.0",
            "express": "^4.17.1",
            "moment": "^2.29.1",
            "os": "^0.1.2",
            "sourcebin_js": "0.0.3-ignore"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-02-11
      • 2016-09-28
      • 2021-07-31
      • 2017-07-17
      • 2018-03-20
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多