错误:在Heroku上找不到模块Discord.js [英] Error: cannot find module Discord.js on Heroku

查看:114
本文介绍了错误:在Heroku上找不到模块Discord.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不和谐的机器人已经有几个星期了,并且一切运行正常。今天我在git仓库中添加了一条命令,突然heroku向我显示了此错误:

I've had a discord bot for a few weeks and everything has been working perfectly. Today I added a command on my git repository and suddenly heroku showed me this error:


错误:找不到模块'discord.js'

Error: Cannot find module 'discord.js'

我没有更改主要bot代码或package.json文件中的任何内容。我删除了添加的新命令,并再次推送了新的更改,但仍然遇到相同的错误。
我尝试使用 npm install discord.js --save 重新安装discord.js,并使用新版本更新package.json。仍然没有。

I didn't change anything in the main bot code nor in the package.json file. I removed the new command I added and pushed the new changes again, and still got the same error. I tried to reinstall discord.js with npm install discord.js --save and updated the package.json with the new version. Still nothing.

如果我在本地运行该机器人,它将起作用,并且如果我回滚到Heroku上的最后一个可用版本,它也将起作用。

The bot works if I run it locally, and it also works if I roll back to the last working build on Heroku.

我的bot.js代码加载库:

My bot.js code to load the library:

const Discord = require("discord.js");

我的package.json文件:

My package.json file:

{
  "name": "redacted",
  "description": "redacted",
  "version": "1.0.0",
  "main": "bot.js",
  "scripts": {
    "start": "node bot.js"
  },
  "dependencies": {
    "discord.js": "^11.5.1",
    "request": "2.81.0"
  }
}

我不知道该怎么做,因为代码与以前的版本完全相同。我不明白为什么会收到此错误。

I don't know what to do because the code is exactly the same as the previous versions. I don't understand why I'm getting this error.

推荐答案

我相信错误可能出在您的软件包中.json 文件,您缺少一些关键事项:

I believe the error may lie in your package.json file, you are a missing a few key things:

您必须同时包含用于 node npm (我建议使用最新的):

You must include the versions to use for both node and npm (I'd recommend using the latest):

"engines": {
  "node": "12.14.1",
  "npm": "6.13.4"
},

接下来,您还需要像这样定义 git存储库

Next you need to also define your git repository like so:

"repository": {
  "type": "git",
  "url": "git+link"
},

还要确保在您的 Procfile 中,您具有:

As well make sure in your Procfile you have:

worker: npm start

在您的 requirements.txt中确保具有:

npm install discord.js

您可以阅读更多有关托管您的信息r。Heroku上的discord.js机器人此处。

You can read more on hosting your discord.js bot on Heroku here.

这篇关于错误:在Heroku上找不到模块Discord.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆