【Azure Bot Service】部署NodeJS ChatBot代码到App Service中无法自动启动

本文涉及的产品
应用实时监控服务-应用监控,每月50GB免费额度
任务调度 XXL-JOB 版免费试用,400 元额度,开发版规格
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: 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'

问题描述

把NodeJS的ChatBot代码部署到App Service环境中,通过VS Code直接部署,显示部署成功。但是通过URL访问时候,却是 :( Application Error 。

问题解答

App Service遇见Application Error,第一步,查看日志。

发现启动时候遇见:

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'

因在部署NodeJS项目时,VS Code打包时候,排除了 项目中 node_modules文件夹中的全部内容。导致项目启动时候找不到module!

8:21:29 PM lbbotbackendapp01: Starting deployment...

8:21:29 PM lbbotbackendapp01: Creating zip package...

8:21:30 PM lbbotbackendapp01: Ignoring files from "appService.zipIgnorePattern"

"node_modules{,/**}"

".vscode{,/**}"

8:21:31 PM lbbotbackendapp01: Adding 13 files to zip package...

而部署包上传成功后,App Service并没有主动执行npm install安装系统中所需要使用的node modules。

 

解决办法有多种:

方式一:修改zipIgnorePattern内容,让Zip部署包中包含本地可以运行的程序的全部文件。重新部署!

 

方式二:直接进入App Service的高级工具Kudu站点(https://<yourappservicename>.scm.chinacloudsites.cn/newui/kududebug), 进入wwwroot目录,执行 npm install

但是,这种方式有时会遇见权限不足,无法安装modules问题, 所以,还是更推荐第一种方式,从本地上传完整的node modules文件!

npm ERR! Error: EACCES: permission denied, rename '/home/site/wwwroot/node_modules/eslint-plugin-import' -> '/home/site/wwwroot/node_modules/.eslint-plugin-import-QTkaoisN'

此外,如果完整的NodeJS项目文件部署到App Service后,项目无法启动的原因也可能为:

从 Node 14 LTS 开始,容器不会自动使用 PM2 启动应用。 若要使用 PM2 启动应用,请将启动命令设置为 pm2 start <.js-file-or-PM2-file> --no-daemon。

请务必使用 --no-daemon 参数,因为 PM2 需要在前台运行才能使容器正常工作。

 

参考资料

为 Azure 应用服务配置 Node.js 应用 : https://docs.azure.cn/zh-cn/app-service/configure-language-nodejs?pivots=platform-linux#configure-nodejs-server

 

【END】



 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
14天前
|
应用服务中间件 Linux nginx
【Azure App Service】基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?
基于Linux创建的App Service是否可以主动升级内置的Nginx版本呢?Web App Linux 默认使用的 Nginx 版本是由平台预定义的,无法更改这个版本。
126 77
|
6天前
|
弹性计算 JavaScript 前端开发
一键安装!阿里云新功能部署Nodejs环境到ECS竟然如此简单!
Node.js 是一种高效的 JavaScript 运行环境,基于 Chrome V8 引擎,支持在服务器端运行 JavaScript 代码。本文介绍如何在阿里云上一键部署 Node.js 环境,无需繁琐配置,轻松上手。前提条件包括 ECS 实例运行中且操作系统为 CentOS、Ubuntu 等。功能特点为一键安装和稳定性好,支持常用 LTS 版本。安装步骤简单:登录阿里云控制台,选择扩展程序管理页面,安装 Node.js 扩展,选择实例和版本,等待创建完成并验证安装成功。通过阿里云的公共扩展,初学者和经验丰富的开发者都能快速进入开发状态,开启高效开发之旅。
|
18天前
|
C#
【Azure Function】Function App出现System.IO.FileNotFoundException异常
Exception while executing function: xxxxxxx,The type initializer for 'xxxxxx.Storage.Adls2.StoreDataLakeGen2Reading' threw an exception. Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the
113 64
|
20天前
|
监控 关系型数据库 MySQL
|
8天前
|
弹性计算 JavaScript 前端开发
一键安装!阿里云新功能部署Nodejs环境到ECS竟然如此简单!
一键安装!阿里云新功能部署Nodejs环境到ECS竟然如此简单!
一键安装!阿里云新功能部署Nodejs环境到ECS竟然如此简单!
|
3天前
|
JavaScript API
【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
Running your function in portal requires the app to explicitly accept requests from https://portal.azure.cn. This is known as cross-origin resource sharing (CORS).Configure CORS to add https://portal.azure.cn to allowed origins.
|
1月前
|
Windows
【Azure App Service】对App Service中CPU指标数据中系统占用部分(System CPU)的解释
在Azure App Service中,CPU占比可在App Service Plan级别查看整个实例的资源使用情况。具体应用中仅能查看CPU时间,需通过公式【CPU Time / (CPU核数 * 60)】估算占比。CPU百分比适用于可横向扩展的计划(Basic、Standard、Premium),而CPU时间适用于Free或Shared计划。然而,CPU Percentage包含所有应用及系统占用的CPU,高CPU指标可能由系统而非应用请求引起。详细分析每个进程的CPU占用需抓取Windows Performance Trace数据。
88 40
|
2月前
|
API
【Azure Logic App】使用Logic App来定制Monitor Alert邮件内容遇见无法获取SearchResults的情况
Log search alert rules from API version 2020-05-01 use this payload type, which only supports common schema. Search results aren't embedded in the log search alerts payload when you use this version.
51 10
|
3月前
|
缓存 容器 Perl
【Azure Container App】Container Apps 设置延迟删除 (terminationGracePeriodSeconds) 的解释
terminationGracePeriodSeconds : 这个参数的定义是从pod收到terminated signal到最终shutdown的最大时间,这段时间是给pod中的application 缓冲时间用来处理链接关闭,应用清理缓存的;并不是从idel 到 pod被shutdown之间的时间;且是最大时间,意味着如果application 已经gracefully shutdown,POD可能被提前terminated.