程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了部署 + 使用 CLI 客户端时 Heroku 应用程序错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决部署 + 使用 CLI 客户端时 Heroku 应用程序错误?

开发过程中遇到部署 + 使用 CLI 客户端时 Heroku 应用程序错误的问题如何解决?下面主要结合日常开发的经验,给出你关于部署 + 使用 CLI 客户端时 Heroku 应用程序错误的解决方法建议,希望对你解决部署 + 使用 CLI 客户端时 Heroku 应用程序错误有所启发或帮助;

我正在处理一个项目,其中我必须让 Node.Js Cli 客户端与 Heroku 服务器通信。

我尝试部署一个简单的聊天应用程序示例以确保一切正常,但遇到了 Heroku 错误,提示“应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请检查您的日志以获取详细信息。您可以从 Heroku Cli 使用命令 heroku logs --tail"

这是我运行上述命令时的 Heroku 日志,我很确定该错误与服务器在部署时无法加载 socket-io 模块有关:

2021-04-26T00:05:05.310536+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-26T00:05:05.310536+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-04-26T00_05_05_288Z-deBUG.log
2021-04-26T00:05:05.386444+00:00 heroku[web.1]: Process exited with status 1
2021-04-26T00:05:05.490453+00:00 heroku[web.1]: State changed from starTing to crashed
2021-04-26T00:05:05.494874+00:00 heroku[web.1]: State changed from crashed to starTing
2021-04-26T00:05:08.142848+00:00 heroku[web.1]: StarTing process with command `npm start`
2021-04-26T00:05:11.291774+00:00 app[web.1]:
2021-04-26T00:05:11.291802+00:00 app[web.1]: > test@1.0.0 start /app
2021-04-26T00:05:11.291802+00:00 app[web.1]: > node index.Js
2021-04-26T00:05:11.291802+00:00 app[web.1]:
2021-04-26T00:05:11.374875+00:00 app[web.1]: internal/modules/cJs/loader.Js:883
2021-04-26T00:05:11.374878+00:00 app[web.1]: throw err;
2021-04-26T00:05:11.374879+00:00 app[web.1]: ^
2021-04-26T00:05:11.374879+00:00 app[web.1]:
2021-04-26T00:05:11.374880+00:00 app[web.1]: Error: CAnnot find module 'socket.io'
2021-04-26T00:05:11.374880+00:00 app[web.1]: require stack:
2021-04-26T00:05:11.374880+00:00 app[web.1]: - /app/index.Js
2021-04-26T00:05:11.374881+00:00 app[web.1]: at Function.Module._resolvefilename (internal/modules/cJs/loader.Js:880:15)
2021-04-26T00:05:11.374881+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:725:27)
2021-04-26T00:05:11.374882+00:00 app[web.1]: at Module.require (internal/modules/cJs/loader.Js:952:19)
2021-04-26T00:05:11.374882+00:00 app[web.1]: at require (internal/modules/cJs/Helpers.Js:88:18)
2021-04-26T00:05:11.374882+00:00 app[web.1]: at Object.<anonymous> (/app/index.Js:2:12)
2021-04-26T00:05:11.374883+00:00 app[web.1]: at Module._compile (internal/modules/cJs/loader.Js:1063:30)
2021-04-26T00:05:11.374883+00:00 app[web.1]: at Object.Module._extensions..Js (internal/modules/cJs/loader.Js:1092:10)
2021-04-26T00:05:11.374883+00:00 app[web.1]: at Module.load (internal/modules/cJs/loader.Js:928:32)
2021-04-26T00:05:11.374887+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:769:14)
2021-04-26T00:05:11.374888+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.Js:72:12) {
2021-04-26T00:05:11.374888+00:00 app[web.1]: code: 'MODulE_NOT_FOUND',2021-04-26T00:05:11.374889+00:00 app[web.1]: requireStack: [ '/app/index.Js' ]
2021-04-26T00:05:11.374889+00:00 app[web.1]: }
2021-04-26T00:05:11.407116+00:00 app[web.1]: npm ERR! code EliFECYCLE
2021-04-26T00:05:11.407516+00:00 app[web.1]: npm ERR! errno 1
2021-04-26T00:05:11.416214+00:00 app[web.1]: npm ERR! test@1.0.0 start: `node index.Js`
2021-04-26T00:05:11.416464+00:00 app[web.1]: npm ERR! Exit status 1
2021-04-26T00:05:11.416760+00:00 app[web.1]: npm ERR!
2021-04-26T00:05:11.416976+00:00 app[web.1]: npm ERR! Failed at the test@1.0.0 start script.
2021-04-26T00:05:11.417532+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-04-26T00:05:11.430755+00:00 app[web.1]:
2021-04-26T00:05:11.431385+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-26T00:05:11.431600+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-04-26T00_05_11_418Z-deBUG.log
2021-04-26T00:05:11.505552+00:00 heroku[web.1]: Process exited with status 1
2021-04-26T00:05:11.580749+00:00 heroku[web.1]: State changed from starTing to crashed
2021-04-26T00:05:13.627279+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slingshot-test-nodeJs.herokuapp.com request_ID=41d7f800-0833-45ac-9a24-e9e984981929 fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https
2021-04-26T00:05:13.811879+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=slingshot-test-nodeJs.herokuapp.com request_ID=de243ea9-c7e1-4a74-91bd-4da78834b085 fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https
2021-04-26T00:13:06.000000+00:00 app[API]: Build started by user hbagalkote@gmail.com
2021-04-26T00:13:23.000000+00:00 app[API]: Build succeeded
2021-04-26T00:13:23.403605+00:00 app[API]: Deploy 12d7e839 by user hbagalkote@gmail.com
2021-04-26T00:13:23.403605+00:00 app[API]: Release v8 created by user hbagalkote@gmail.com
2021-04-26T00:13:23.552491+00:00 heroku[web.1]: State changed from crashed to starTing
2021-04-26T00:13:26.818012+00:00 heroku[web.1]: StarTing process with command `node index.Js`
2021-04-26T00:13:29.914344+00:00 app[web.1]: internal/modules/cJs/loader.Js:883
2021-04-26T00:13:29.914388+00:00 app[web.1]: throw err;
2021-04-26T00:13:29.914388+00:00 app[web.1]: ^
2021-04-26T00:13:29.914389+00:00 app[web.1]:
2021-04-26T00:13:29.914389+00:00 app[web.1]: Error: CAnnot find module 'socket.io'
2021-04-26T00:13:29.914390+00:00 app[web.1]: require stack:
2021-04-26T00:13:29.914390+00:00 app[web.1]: - /app/index.Js
2021-04-26T00:13:29.914391+00:00 app[web.1]: at Function.Module._resolvefilename (internal/modules/cJs/loader.Js:880:15)
2021-04-26T00:13:29.914391+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:725:27)
2021-04-26T00:13:29.914391+00:00 app[web.1]: at Module.require (internal/modules/cJs/loader.Js:952:19)
2021-04-26T00:13:29.914392+00:00 app[web.1]: at require (internal/modules/cJs/Helpers.Js:88:18)
2021-04-26T00:13:29.914392+00:00 app[web.1]: at Object.<anonymous> (/app/index.Js:2:12)
2021-04-26T00:13:29.914392+00:00 app[web.1]: at Module._compile (internal/modules/cJs/loader.Js:1063:30)
2021-04-26T00:13:29.914392+00:00 app[web.1]: at Object.Module._extensions..Js (internal/modules/cJs/loader.Js:1092:10)
2021-04-26T00:13:29.914393+00:00 app[web.1]: at Module.load (internal/modules/cJs/loader.Js:928:32)
2021-04-26T00:13:29.914393+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:769:14)
2021-04-26T00:13:29.914394+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.Js:72:12) {
2021-04-26T00:13:29.914394+00:00 app[web.1]: code: 'MODulE_NOT_FOUND',2021-04-26T00:13:29.914394+00:00 app[web.1]: requireStack: [ '/app/index.Js' ]
2021-04-26T00:13:29.914395+00:00 app[web.1]: }
2021-04-26T00:13:29.974925+00:00 heroku[web.1]: Process exited with status 1
2021-04-26T00:13:30.067473+00:00 heroku[web.1]: State changed from starTing to crashed
2021-04-26T00:13:32.450999+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slingshot-test-nodeJs.herokuapp.com request_ID=37d17d3f-c2b0-4bca-b1ca-36eb952e09de fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https
2021-04-26T00:13:32.618072+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=slingshot-test-nodeJs.herokuapp.com request_ID=13ff0bcf-2201-46d9-84ac-d05c91bd12ef fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https
2021-04-26T00:16:34.224143+00:00 heroku[web.1]: State changed from crashed to starTing
2021-04-26T00:16:36.722190+00:00 heroku[web.1]: StarTing process with command `node index.Js`
2021-04-26T00:16:38.725268+00:00 app[web.1]: internal/modules/cJs/loader.Js:883
2021-04-26T00:16:38.725295+00:00 app[web.1]: throw err;
2021-04-26T00:16:38.725296+00:00 app[web.1]: ^
2021-04-26T00:16:38.725296+00:00 app[web.1]:
2021-04-26T00:16:38.725296+00:00 app[web.1]: Error: CAnnot find module 'socket.io'
2021-04-26T00:16:38.725296+00:00 app[web.1]: require stack:
2021-04-26T00:16:38.725297+00:00 app[web.1]: - /app/index.Js
2021-04-26T00:16:38.725297+00:00 app[web.1]: at Function.Module._resolvefilename (internal/modules/cJs/loader.Js:880:15)
2021-04-26T00:16:38.725297+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:725:27)
2021-04-26T00:16:38.725298+00:00 app[web.1]: at Module.require (internal/modules/cJs/loader.Js:952:19)
2021-04-26T00:16:38.725298+00:00 app[web.1]: at require (internal/modules/cJs/Helpers.Js:88:18)
2021-04-26T00:16:38.725298+00:00 app[web.1]: at Object.<anonymous> (/app/index.Js:2:12)
2021-04-26T00:16:38.725298+00:00 app[web.1]: at Module._compile (internal/modules/cJs/loader.Js:1063:30)
2021-04-26T00:16:38.725299+00:00 app[web.1]: at Object.Module._extensions..Js (internal/modules/cJs/loader.Js:1092:10)
2021-04-26T00:16:38.725299+00:00 app[web.1]: at Module.load (internal/modules/cJs/loader.Js:928:32)
2021-04-26T00:16:38.725299+00:00 app[web.1]: at Function.Module._load (internal/modules/cJs/loader.Js:769:14)
2021-04-26T00:16:38.725300+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.Js:72:12) {
2021-04-26T00:16:38.725300+00:00 app[web.1]: code: 'MODulE_NOT_FOUND',2021-04-26T00:16:38.725300+00:00 app[web.1]: requireStack: [ '/app/index.Js' ]
2021-04-26T00:16:38.725301+00:00 app[web.1]: }
2021-04-26T00:16:38.775108+00:00 heroku[web.1]: Process exited with status 1
2021-04-26T00:16:38.832146+00:00 heroku[web.1]: State changed from starTing to crashed
2021-04-26T00:17:40.388694+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=slingshot-test-nodeJs.herokuapp.com request_ID=f42d0aaf-a1db-4f6a-8888-063084139ca2 fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https
2021-04-26T00:17:40.499806+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=slingshot-test-nodeJs.herokuapp.com request_ID=34f18224-8dfd-40aa-93db-78ad61880e63 fwd="24.196.239.75" dyno= connect= service= status=503 bytes= protocol=https

此外,我的 procfile 中有 web: node index.Js

我不太确定为什么会发生这种情况,因为我在本地安装了 socket-io,并且在本地测试时服务器和客户端工作正常。

我的第二个问题是关于客户端和服务器代码。由于我可以在本地测试时对端口值进行硬编码,因此客户端和服务器进行通信。但是,我如何让客户端与 Heroku 中运行的 index.Js 代码对话(假设我解决了第一个问题)?

我的客户端 (clIEnt.Js) 和服务器 (index.Js) 代码如下:

//server code

const http = require('http').createServer()
const io = require('socket.io')(http)
const port = process.env.PORT || 3000

http.Listen(port,() => console.log('server Listening on port: ' + port))

io.on('connection',(socket) => {
    console.log('connected')
    socket.on('message',(evt) => {
        console.log(evt)
        socket.broadcast.emit('message',evt)
    })
})
//clIEnt code

//ObvIoUsly,this localhost value will not work,but what should I change it to instead?
var socket = require('socket.io-clIEnt')('http://localhost:3000')
const repl = require('repl')
const chalk = require('chalk')
var username = null

socket.on('disconnect',function() {
    socket.emit('disconnect')
})

socket.on('connect',() => {
    console.log(chalk.red('== start chatTing =='))
    username = process.argv[2]
})

socket.on('message',(data) => {
    const { cmd,username } = data
    console.log(chalk.green(username + ': ' + cmd.split("\n")[0]))
})

repl.start({
    prompt: '',eval: (cmd) => {
        socket.send({CR_493_11845@d,usernamE})
    }
})

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的部署 + 使用 CLI 客户端时 Heroku 应用程序错误全部内容,希望文章能够帮你解决部署 + 使用 CLI 客户端时 Heroku 应用程序错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:+使用部署