简体   繁体   English

在 Heroku 上部署节点应用程序时出现问题 – 构建成功,但返回错误:找不到模块“请求”

[英]Problem deploying node app on Heroku – build successful, but returns Error: Cannot find module 'request'

I´m still experimenting with node and this modern architecture with javascript, react and so on.我仍在用 javascript、react 等尝试使用 node 和这种现代架构。 But I have a lot of experience with web development (PHP, ASP.NET).但是我在 web 开发(PHP,ASP.NET)方面有很多经验。 Anyway, I´m working on transcoding of my old frameworks to node and trying out Heroku to host it.无论如何,我正在将我的旧框架转码为节点并尝试使用 Heroku 来托管它。 At the beginning stages, I had managed to deploy and make my application run completely in the web to test it out.在开始阶段,我设法部署并让我的应用程序完全在 web 中运行以进行测试。 Then, I started to work on many other parts from my application and never tested the deploy again, until now.然后,我开始处理我的应用程序的许多其他部分,直到现在才再次测试部署。

I already searched the full day to debug the problems that were occurring and managed to get to a point where the build in Heroku is successful.我已经搜索了一整天来调试正在发生的问题,并设法达到 Heroku 中的构建成功的程度。 The problem is that when I run the access the address where was supposed to work, it returns me a generic error:问题是,当我运行访问应该工作的地址时,它会返回一个通用错误:

at=error code=H10 desc="App crashed" method=GET path="/system" host=syncsystem-multiplatform-v1.herokuapp.com request_id=9c7e251e-4947-45cb-928e-674148718045 fwd="186.231.136.56" dyno= connect= service= status=503 bytes= protocol=http at=error code=H10 desc="App crashed" method=GET path="/system" host=syncsystem-multiplatform-v1.herokuapp.com request_id=9c7e251e-4947-45cb-928e-674148718045 fwd="186.231.136.56" dyno=连接=服务=状态=503字节=协议=http

And in the “view logs” section, this is what is displayed:在“查看日志”部分,显示如下:

    2021-04-14T21:05:29.722072+00:00 heroku[web.1]: State changed from crashed to starting
    2021-04-14T21:05:38.899481+00:00 heroku[web.1]: Starting process with command `node app`
    2021-04-14T21:05:46.776113+00:00 heroku[web.1]: Process exited with status 1
    2021-04-14T21:05:46.851815+00:00 heroku[web.1]: State changed from starting to crashed
    2021-04-14T21:05:46.551799+00:00 app[web.1]: internal/modules/cjs/loader.js:626
    2021-04-14T21:05:46.551865+00:00 app[web.1]:     throw err;
    2021-04-14T21:05:46.551866+00:00 app[web.1]:     ^
    2021-04-14T21:05:46.551866+00:00 app[web.1]: 
    2021-04-14T21:05:46.551866+00:00 app[web.1]: Error: Cannot find module 'request'
    2021-04-14T21:05:46.551867+00:00 app[web.1]: Require stack:
    2021-04-14T21:05:46.551867+00:00 app[web.1]: - /app/app.js
    2021-04-14T21:05:46.551872+00:00 app[web.1]:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    2021-04-14T21:05:46.551872+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    2021-04-14T21:05:46.551877+00:00 app[web.1]:     at Module.require (internal/modules/cjs/loader.js:681:19)
    2021-04-14T21:05:46.551878+00:00 app[web.1]:     at require (internal/modules/cjs/helpers.js:16:16)
    2021-04-14T21:05:46.551878+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:20:17)
    2021-04-14T21:05:46.551878+00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:774:30)
    2021-04-14T21:05:46.551879+00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    2021-04-14T21:05:46.551879+00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:641:32)
    2021-04-14T21:05:46.551879+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    2021-04-14T21:05:46.551879+00:00 app[web.1]:     at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) {
    2021-04-14T21:05:46.551884+00:00 app[web.1]:   code: 'MODULE_NOT_FOUND',
    2021-04-14T21:05:46.551885+00:00 app[web.1]:   requireStack: [ '/app/app.js' ]
    2021-04-14T21:05:46.551885+00:00 app[web.1]: }

During the research I did to debug, I found these main points: 1 - In my Procfile, I´ve got this line: web: node app在我进行调试的研究期间,我发现了以下要点: 1 - 在我的 Procfile 中,我有这一行:web: node app

2 - On my package. 2 - 在我的 package 上。 Json, I understand that this part is essential: Json,我明白这部分是必不可少的:

    "scripts": {
        "start": "node app"
    },

3 – On my main app.js, I´ve got the configuration done with Heroku´s server variables: 3 – 在我的主 app.js 上,我已经使用 Heroku 的服务器变量完成了配置:

    app.listen(process.env.PORT || process.env.CONFIG_SYSTEM_PORT, ()=>{
        if(gSystemConfig.configDebug === true)
        {
            console.log(`app running on port: ${ process.env.PORT || process.env.CONFIG_SYSTEM_PORT }`);
        }
    });

4 – I´ve disabled cache on server variables by Heroku´s app settings: NODEMODULESCACHE=false 4 – 我已经通过 Heroku 的应用设置禁用了服务器变量缓存:NODEMODULESCACHE=false

5 – I´ve set up a linked github repository to make the deploy automatic: https://github.com/jorge-mauricio/syncsystem-multiplatformv1-dev/tree/master 5 – 我已经建立了一个链接的 github 存储库以使部署自动化: https://github.com/jorge-mauricio/syncsystem-multiplatformv1-dev/tree/master

If anyone needs to take a look at the full source code, it´s on a github repository: https://github.com/jorge-mauricio/syncsystem-multiplatformv1-dev/tree/master如果有人需要查看完整的源代码,它位于 github 存储库: https://github.com/jorge-mauricio/syncsystem-multiplatformv1-dev/tree/master

There are some react folders in it, but that´s not the main focus now.其中有一些反应文件夹,但这不是现在的主要焦点。 The main focus is to run the application in node (app.js, backend_node, components_node), which, by the way, is running perfectly on the local environment.主要重点是在节点(app.js、backend_node、components_node)中运行应用程序,顺便说一下,它在本地环境中运行良好。

The online address where is supposed to load a login screen, is at: http://syncsystem-multiplatform-v1.herokuapp.com/system应该加载登录屏幕的在线地址是: http://syncsystem-multiplatform-v1.herokuapp.com/system

Anyone has any ideas of what I could be missing out?有人对我可能会错过什么有任何想法吗?

Thanks, Jorge Mauricio谢谢,豪尔赫毛里西奥

It looks the problem is exactly what the output error says: it cannot find the module request .看起来问题正是 output 错误所说的:它找不到模块request In your file package.json , you specify the libraries (modules) you're using, and request seems to be missing from there.在您的文件package.json中,您指定了您正在使用的库(模块),并且那里似乎缺少request

When you do for example npm install express (or yarn add express , same thing), you add this library to your package.json file.例如,当您执行npm install express (或yarn add express ,同样的事情)时,您将此库添加到您的package.json文件中。 Heroku starts by getting these dependencies from package.json , so that they then can be required. Heroku 首先从package.json获取这些依赖项,以便随后需要它们。

Also, from the looks of it, the request library has been deprecated .此外,从外观上看,请求库已被弃用 I would suggest switching to axios which seems to fulfill the same needs.我建议切换到axios似乎可以满足相同的需求。

EDIT: I see now that the module is actually listed in package-lock.json , so there shouldn't be a problem with it.编辑:我现在看到该模块实际上列在package-lock.json中,所以应该没有问题。 However, you can try running npm install request to add it manually, then deploying to Heroku.但是,您可以尝试运行npm install request以手动添加它,然后部署到 Heroku。 That way, you can see if the problem seems to lie with Heroku configs or with the module itself.这样,您可以查看问题似乎在于 Heroku 配置或模块本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM