Heroku上已部署但未安装依赖项的代码

时间:2020-01-22 06:59:19

标签: node.js heroku discord.js

我试图将Discord JS应用程序部署到Heroku。部署后,该节点似乎已经安装了所有依赖项。但是在应用程序日志中,它在那里丢失了。

这是我最新的构建日志

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  10.16.3
       engines.npm (package.json):   6.9.0

       Resolving node version 10.16.3...
       Downloading and installing node 10.16.3...
       npm 6.9.0 already installed with node

-----> Restoring cache
       - node_modules (not cached - skipping)

-----> Installing dependencies
       Installing node modules (package.json)
       up to date in 0.303s
       found 0 vulnerabilities


-----> Build

-----> Caching build
       - node_modules (nothing to cache)

-----> Pruning devDependencies
       up to date in 0.282s
       found 0 vulnerabilities


-----> Build succeeded!
-----> Discovering process types
       Procfile declares types     -> worker
       Default types for buildpack -> web
-----> Compressing...
       Done: 19.3M
-----> Launching...
       Released v15
       https://botcia-discordjs.herokuapp.com/ deployed to Heroku

我认为部署似乎没有任何问题。但是然后我从应用程序日志中遇到了一个错误,因此该机器人无法启动。

2020-01-22T06:47:36.137591+00:00 heroku[worker.1]: State changed from crashed to starting
2020-01-22T06:47:37.772565+00:00 heroku[worker.1]: Starting process with command `node main.js`
2020-01-22T06:47:38.336892+00:00 heroku[worker.1]: State changed from starting to up
2020-01-22T06:47:39.738190+00:00 heroku[worker.1]: State changed from up to crashed
2020-01-22T06:47:39.721156+00:00 heroku[worker.1]: Process exited with status 1
2020-01-22T06:47:39.657493+00:00 app[worker.1]: internal/modules/cjs/loader.js:638
2020-01-22T06:47:39.657520+00:00 app[worker.1]:     throw err;
2020-01-22T06:47:39.657522+00:00 app[worker.1]:     ^
2020-01-22T06:47:39.657523+00:00 app[worker.1]: 
2020-01-22T06:47:39.657525+00:00 app[worker.1]: Error: Cannot find module 'discord.js'
//more error

实际上发现的第一个错误是找不到模块的东西。因此,如果我设法修复discord.js,就会遇到另一个问题。 我的package.json文件:

{
  "name": "xxxxx",
  "version": "1",
  "main": "main.js",
  "license": "MIT",
  "scripts": {
    "start": "node main.js"
  },
  "dependencies": {
    "discord.js": "^11.5.1",
    "dotenv": "^8.2.0",
    "fs": "^0.0.1-security",
    "moment": "^2.24.0",
    "youtube-info": "^1.3.2"
  },
  "engines": {
    "node": "10.16.3",
    "npm": "6.9.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/xxxx/xxxx"
  },
  "author": "XXXX <xxxxxxxxx@gmail.com>",
  "private": false
}

Procfile文件:

worker: node main.js

requirements.txt文件:

npm install discord.js

请注意,我使用GUI而非网站CLI来部署服务器。所以我不知道如何在没有CLI的情况下解决它。

1 个答案:

答案 0 :(得分:0)

您只需要部署应用程序,然后在 CLI 中编写 npm install。它将安装 package.json 中定义的所有包。