[英]package.json issue while deploying a node api on Azure App Service
I wish to deploy a node api on Azure App Service using Github Actions.我希望使用 Github 操作在 Azure 应用服务上部署节点 api。 The app I wish to deploy is on a subfolder called "api" of the repository.
我希望部署的应用程序位于存储库的名为“api”的子文件夹中。
The Github Actions part works fine, but the website doesn't work, and when I look in the logs, it shows this error: "Error: Cannot find module '../package.json'". Github Actions 部分工作正常,但网站无法正常工作,当我查看日志时,它显示此错误:“错误:找不到模块 '../package.json'”。
The app should look for package.json in./, I don't know why it is searching in../.该应用程序应该在./ 中寻找 package.json,我不知道它为什么在../ 中搜索。
Here is my Github Actions yaml:这是我的 Github 操作 yaml:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Node.js app to Azure Web App - hobbeez
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js version
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
working-directory: api
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: node-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: node-app
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'hobbeez'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_16C52153CB9348578BF747E038921ED6 }}
package: .
I added a ".deployment" file at the root of the repository to specify that it should deploy the "api" subfolder, here is what this file contains:我在存储库的根目录中添加了一个“.deployment”文件,以指定它应该部署“api”子文件夹,这是该文件包含的内容:
[config]
project = api
I tried to search for the answer for weeks, but I didn't manage to find a solution.我试图寻找答案数周,但我没有设法找到解决方案。 Does anyone have an idea of what am I doing wrong?
有谁知道我做错了什么?
Thanks in advance.提前致谢。
index.js
or app.js
file has to be under src
folderindex.js
或app.js
文件必须在src
文件夹下package.json
, add the start script as index.js
or app.js
based on your scriptpackage.json
中,根据您的脚本将启动脚本添加为index.js
或app.js
"start": "node src/index.js",
[config] project = api
Yes, the way you specified is correct to deploy a subfolder.是的,您指定的方式对于部署子文件夹是正确的。
Cannot find module '../package.json
找不到模块'../package.json
Remove the node_modules
folder and package-lock.json
and run npm install
again删除
node_modules
文件夹和package-lock.json
并再次运行npm install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.