- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我第一次尝试将node.js应用程序作为Azure应用程序服务部署到Azure,但在尝试运行该应用程序时遇到了这个顽固的错误,我还没有弄清楚如何进行故障排除。也许这里有人对我犯错误的地方有一些提示。
提供一些背景:
考虑到这一点,我的项目文件夹结构如下所示:
| main_folder
| .github
| workflows
workflow.yml
| server
| src
| dist
.env
index.ts
package-lock.json
package.json
tsconfig.json
| other_apps
.gitignore
README.md
在 index.ts
中,我有与运行应用程序相关的代码。其余相关文件如下所示:tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"lib": [
"ES2022", "DOM"
],
"strict": true,
"rootDir": ".",
"outDir": "./dist",
"sourceMap": true,
"esModuleInterop": true
}
}
package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node-dev --transpile-only --no-notify --exit-child index.ts",
"build": "npx tsc",
"start": "node ."
},
// ...
}
workflow.yml
on:
push:
branches: ["master"]
workflow_dispatch:
env:
AZURE_WEBAPP_NAME: my-app-name
AZURE_WEBAPP_PACKAGE_PATH: "." # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: "16.x" # set this to the node version to use
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
cache-dependency-path: ./server/package-lock.json
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Zip artifact for deployment
run: zip -r release.zip ./* .env
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: node-app
path: ./server/release.zip
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: "Development"
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: node-app
- name: unzip artifact for deployment
run: unzip release.zip
- name: "Deploy to Azure WebApp"
id: my_app_id
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
这个应用程序在本地运行得非常好(运行npm run dev
)。当我推送到 GitHub 中的 master
时,构建和部署作业都正常工作。但是,当我转到 Azure 门户并检查该应用程序时,我看到以下两件事:
错误为错误:找不到模块“/home/site/wwwroot/index.js”
。在 GitHub 中设置自动构建和部署的配置时,我遇到了项目结构的几个问题,因为我的 git 存储库实际上不包含任何应用程序 (package.json),但它们位于嵌套文件夹中。但是,我认为这个错误不是源于该设置,而是源于其他地方。
有人可以提示我我在这里做错了什么吗?我要重复一遍,这是我第一次尝试将 Nodejs 应用程序发布到 Azure,尽管我认为我正确地遵循了文档,但我有可能在一个明显的步骤中搞砸了。如果是这样的话,我将不胜感激有人指出这一点!
我很乐意在描述中添加可能与该问题相关的更多信息。
最佳答案
我尝试通过创建示例 Node.js Web 应用程序来重现此问题,并将代码推送到 github。
使用 github actions CI/CD 管道创建 Azure 应用服务并成功部署。
确保您具有以下项目结构:
使用门户中的 azure 应用服务的发布配置文件在 GitHub 中创建 key ,如下图所示:
配置完上述步骤后,将代码从本地存储库推送到 git 存储库,然后它将触发 github 管道,代码将部署到 azure 应用服务,如下图所示:
您可以转到azure门户并检查部署是否成功,如下所示:
单击 Azure 应用服务 URL 后的输出屏幕:
关于node.js - 如何使用部署到 Azure 的应用程序修复 "Error: Cannot find module '/home/site/wwwroot/index.js”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74005695/
当我使用 Html.ActionLink 时,我发现 @Html.ActionLink("Home", "Index", "home")生成此字符串 Home ,那么为什么地址是\home\index
我有一个现有的 webapi 2 应用程序需要添加基本的前端。现有的 webapi Controller 已在名为 xController yController 的 Controllers 目录根目
我家里有一个应用程序小部件,它会定期更新。如果 HOME 不可见,我想停止更新。我使用一项服务来注册屏幕开/关接收器,以便在屏幕开/关时开始/停止更新应用程序小部件。但我不知道如何检测屏幕是否打开但用
我在使用 create-react-app 时遇到了这个问题,我得到了一个错误: Home does not contain an export named Home. 下面是我如何设置我的 App.
最近我不得不在 .bashrc 中更新我的 JAVA 环境变量 echo $JAVA_HOME # prints out /usr/java/... echo $(JAVA_HOME) # raise
$ cat Makefile all: echo VAR is ${HOME} echo VAR is $${HOME} 给予 $ make echo VAR is /home/abc
我尝试在 google home 模拟器中测试我的项目。直到昨天它还在工作,但今天它显示错误“完成您的请求时出错”网址:“https://console.actions.google.com/proj
我已经实现了具有 OnOff 特性的风扇打开/关闭功能和具有 Fanspeed 特性的风扇模式(“高”、“中”、“低”),现在我想实现百分比 Controller 。例如:将风扇速度设置为 50%。我
我制作了一个小型 Google Home 应用程序,我的服务通过 SimpleMessage + Card 返回响应。 在 console.actions.google.com 模拟器中运行应用程序时
我还在用log4j-1.2.14.jar 在我尝试使用的属性中 log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.app
我正在使用 google smarthome actions for IOT...我更新了我的操作 URL 和帐户链接详细信息。当我尝试在模拟器中启用测试以将我的 TestAPP 部署到云时,它失败并
我在使用 Spring Boot 时遇到了一些问题。 当我使用 @RequestMapping(value = "/home") 时,一切正常。但是当我使用 @RequestMapping(name
起初,文件图标在我的 Ubuntu 20.04 中丢失。后来我运行 sudo root ,但是点击桌面上的图标打开文件还是有些麻烦。现在我运行 sudo nautilus ,我看到 Home 是/ro
我想在 ionic 中制作一个应用程序,所以我通过命令在 ionic 中添加了一些自定义页面: ionic g 页面用户 但是我启动 ionic 服务器它显示错误 Runtime Error Cann
非常感谢您的帮助。 标题说明一切:使用有什么区别: echo `basename $HOME` 和 echo $(basename $HOME) 请注意,我知道 basename 命令的作用,两种语法
在 Rust 中,默认情况下,文件放在 $HOME/.cargo 和 $HOME/.rustup 中。有什么方法可以覆盖这些默认值吗? 我正在尝试调试一个模糊的问题,我想尝试更改文件位置。 最佳答案
我正在尝试以 root 身份备份机器的一些关键文件和目录,包括一些/home 数据,手动挑选一些文件以减小 tarball 大小。大多数情况下一切正常,因为大多数文件无论如何都归 root 所有,但说
如果菜单项是链接,屏幕阅读器应该将其读作“主页、链接、菜单项”还是“主页、菜单项”? 目前,屏幕阅读器将它读作“主页、链接、菜单项”,但我得到的是关于它的混合信息。一些信息说它应该是“主页、链接、菜单
我在一个有多个组织的项目上使用 php codeigniter。每个组织都会有自己的网站,我需要根据组织名称将每个用户重定向到其组织网站。 我得到了部分运行。以本地主机为例: localhost/ap
我正在 Mac OS X 上安装 Ruby on Rails。我遵循的教程说要添加: [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/script
我是一名优秀的程序员,十分优秀!