【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)

简介: 【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)

问题情形

本地NodeJS应用使用Egg脚手架构建,本地运行测试完全没有问题,发布后App Service后不能运行。通过登录到kudu后(https://<your web site>.scm.chinacloudsites.cn)后,在日志中发现找不到一个文件或路径的错误。通过在kudu的CMD窗口执行npm start命令,发现错误是一致,怀疑是对Egg中某个框架的不支持。

详细日志

Application has thrown an uncaught exception and is terminated:

SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory)

    at Object.userInfo (os.js:272:11)

    at module.exports (D:\home\site\wwwroot\pynode\node_modules\node-homedir\index.js:10:26)

    at AppWorkerLoader.getHomedir (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:163:36)

    at AppWorkerLoader.getAppInfo (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:174:23)

    at new EggLoader (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\loader\egg_loader.js:87:25)

    at new AppWorkerLoader (D:\home\site\wwwroot\pynode\node_modules\egg\lib\loader\app_worker_loader.js:9:1)

    at new EggCore (D:\home\site\wwwroot\pynode\node_modules\egg-core\lib\egg.js:118:19)

    at new EggApplication (D:\home\site\wwwroot\pynode\node_modules\egg\lib\egg.js:43:5)

    at new Application (D:\home\site\wwwroot\pynode\node_modules\egg\lib\application.js:60:5)

    at Object.<anonymous> (D:\home\site\wwwroot\pynode\index.js:3:13)

在详细的log文件中,可以看见全面的错误信息。并指出了报错的源文件为:(D:\home\site\wwwroot\pynode\node_modules\node-homedir\index.js:10:26),在源代码中,找出了问题的根源。

问题原因

node_modules\node-homedir\index.js 源码:

1 'use strict';

2

3 const os = require('os');

4

5 module.exports = () => {

6   if (process.env.MOCK_HOME_DIR) return process.env.MOCK_HOME_DIR;

7

8   if (typeof os.userInfo === 'function') {

9     try {

10       const homedir =os.userInfo().homedir;

11       if (homedir) return homedir;

12     } catch (err) {

13       if (err.code !== 'ENOENT') throw err;

14    }

15  }

16

17   if (typeof os.homedir === 'function') {

18     return os.homedir();

19  }

20

21   return process.env.HOME;

22 };

在第十行代码中,使用了os对象,而在App Service中,由于是sandbox 模式下,所以某些操作被禁止了。关于禁止的说明可以参考:https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#general-sandbox-restrictions

解决方案

在查看源代码后,想解决它就有两种办法:

1) 在修改node-homedir\index.js中的源代码,把里面 os.userInfo().homedir 的部分替换成在App Service中的Homedir路径,hardcode这一部分。如  const homedir =”D:\home\site\wwwroot\“;//os.userInfo().homedir;

2) 最快速且无代码改动方案。在App Service的应用程序设置中(Applicaiton Settings)添加一个名MOCK_HOME_DIR的设置,并设置其值为D:\home\site\wwwroot\ (为应用程序发布的默认路径)。 这样node-homedir的源代码就不会进入到os部分。直接在第一行就返回需要的homedir.

 

PS: 这里是把NodeJS的应用发布在Windows的环境中遇见的问题,如发布在App Service For Linux则可以避免类似问题。

相关文章
|
10月前
|
监控 JavaScript 前端开发
深入理解 Nuxt.js 中的 app:error 钩子
【9月更文挑战第25天】在 Nuxt.js 中,`app:error` 钩子是一个强大的工具,用于处理应用程序中的各种错误。它可以在服务器端渲染或客户端运行时触发,帮助提升应用稳定性和用户体验。通过在 `nuxt.config.js` 中定义该钩子,开发者可以实现错误页面显示、错误日志记录及错误恢复等功能,确保应用在遇到问题时能妥善处理并恢复正常运行。
126 10
|
5月前
|
数据采集 JavaScript Android开发
【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
154 7
【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
|
10月前
|
关系型数据库 Unix Shell
File - os.tcsetpgrp(fd, pg)函数
`os.tcsetpgrp(fd, pg)` 函数在进行进程控制和信号管理时非常有用,但它涉及Unix底层的工作原理,因此使用时需具备相应知识,以确保正确和适用,并注意相关的权限和错误处理。
180 61
|
8月前
|
JavaScript C++ 容器
【Azure Bot Service】部署NodeJS ChatBot代码到App Service中无法自动启动
2024-11-12T12:22:40.366223350Z Error: Cannot find module 'dotenv' 2024-11-12T12:40:12.538120729Z Error: Cannot find module 'restify' 2024-11-12T12:48:13.348529900Z Error: Cannot find module 'lodash'
109 11
|
10月前
|
开发者 UED
深入理解 Nuxt.js 中的 app:error 钩子
【9月更文挑战第26天】在 Nuxt.js 中,钩子函数是在特定生命周期阶段执行代码的机制,`app:error` 钩子用于处理应用中的错误,包括服务器端和客户端渲染时出现的问题。它提供了一个集中处理错误的机制,提升了用户体验。当组件渲染过程中出现错误时,`app:error` 钩子会被触发,可以在 `nuxt.config.js` 文件中定义该钩子。通过分析错误对象 `err` 和上下文信息 `context`,开发者可以更好地处理各种错误情况。相比组件内的 `try/catch` 或浏览器原生错误处理,`app:error` 提供了更全局和有针对性的错误处理方式。
130 6
|
10月前
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub的解决之法
An exception occurred while retrieving properties for Event Hub: logicapp. Error Message: 'ClientSecretCredential authentication failed: AADSTS90002: Tenant 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Che
|
11月前
|
C++
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
【Azure Logic App】使用Event Hub 连接器配置 Active Directory OAuth 认证无法成功连接到中国区Event Hub
|
11月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
169 1
|
11月前
|
JavaScript Linux
【Azure App Service for Linux】NodeJS镜像应用启动失败,遇见 RangeError: Incorrect locale information provided
【Azure App Service for Linux】NodeJS镜像应用启动失败,遇见 RangeError: Incorrect locale information provided
225 0

热门文章

最新文章

推荐镜像

更多