Heroku 不下载依赖项

Posted

技术标签:

【中文标题】Heroku 不下载依赖项【英文标题】:Heroku does not download Dependencies 【发布时间】:2020-02-27 00:37:18 【问题描述】:

我希望你能帮助我。我尝试在 Heroku 上部署我的 Discord Bot,但不幸的是它找不到 Discord.js 模块:

错误代码:

2019-10-31T15:35:21.569158+00:00 heroku[worker.1]: State changed from crashed to starting
2019-10-31T15:35:23.457399+00:00 heroku[worker.1]: Starting process with command `node Bot.js`
2019-10-31T15:35:24.147895+00:00 heroku[worker.1]: State changed from starting to up
2019-10-31T15:35:25.778631+00:00 heroku[worker.1]: Process exited with status 1
2019-10-31T15:35:25.838621+00:00 heroku[worker.1]: State changed from up to crashed
2019-10-31T15:35:25.715847+00:00 app[worker.1]: internal/modules/cjs/loader.js:797
2019-10-31T15:35:25.715865+00:00 app[worker.1]:     throw err;
2019-10-31T15:35:25.715866+00:00 app[worker.1]:     ^
2019-10-31T15:35:25.715867+00:00 app[worker.1]: 
2019-10-31T15:35:25.715868+00:00 app[worker.1]: Error: Cannot find module 'discord.js'
2019-10-31T15:35:25.715869+00:00 app[worker.1]: Require stack:
2019-10-31T15:35:25.71587+00:00 app[worker.1]: - /app/Bot.js
2019-10-31T15:35:25.715871+00:00 app[worker.1]:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
2019-10-31T15:35:25.715872+00:00 app[worker.1]:     at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2019-10-31T15:35:25.715873+00:00 app[worker.1]:     at Module.require (internal/modules/cjs/loader.js:849:19)
2019-10-31T15:35:25.715874+00:00 app[worker.1]:     at require (internal/modules/cjs/helpers.js:74:18)
2019-10-31T15:35:25.715875+00:00 app[worker.1]:     at Object.<anonymous> (/app/Bot.js:6:17)
2019-10-31T15:35:25.715876+00:00 app[worker.1]:     at Module._compile (internal/modules/cjs/loader.js:956:30)
2019-10-31T15:35:25.715877+00:00 app[worker.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
2019-10-31T15:35:25.715878+00:00 app[worker.1]:     at Module.load (internal/modules/cjs/loader.js:812:32)
2019-10-31T15:35:25.715879+00:00 app[worker.1]:     at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2019-10-31T15:35:25.715879+00:00 app[worker.1]:     at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10) 
2019-10-31T15:35:25.715881+00:00 app[worker.1]:   code: 'MODULE_NOT_FOUND',
2019-10-31T15:35:25.715882+00:00 app[worker.1]:   requireStack: [ '/app/Bot.js' ]
2019-10-31T15:35:25.715883+00:00 app[worker.1]: 

构建日志:

-----> 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):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 12.x...
       Downloading and installing node 12.13.0...
       Using default npm version: 6.12.0

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

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


-----> Build

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


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

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

还有我的 package.json:



"name": "Date Bot",
"description": "My First Discord Bot",
"version": "1.0.0",
"main": "Bot.js",
"scripts": 
    "start": "node Bot.js"
, "dependencies": 
    "discord.js": "11.3.0"

  


我真的不知道 Heroku 没有安装 Discord.js 的 package.json 文件有什么问题。谷歌这次也没有真正提供帮助。 我希望你能帮助我解决我的问题。

真诚的泷

【问题讨论】:

【参考方案1】:

尝试进入 Heroku 运行命令并输入 npm i discord.js

【讨论】:

以上是关于Heroku 不下载依赖项的主要内容,如果未能解决你的问题,请参考以下文章

无法解决heroku中项目的依赖项

预下载所有依赖项

从 Ivy.xml 下载依赖项

安装依赖项后如何清理heroku中的缓存?

下载网页和依赖项,包括 CSS 图像 [关闭]

Heroku 构建依赖项安装失败