Reputation: 1
I wish to deploy a node api on Azure App Service using Github Actions. The app I wish to deploy is on a subfolder called "api" of the repository.
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'".
The app should look for package.json in ./, I don't know why it is searching in ../ .
Here is my Github Actions 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 :
[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.
Upvotes: 0
Views: 734
Reputation: 7347
index.js
or app.js
file has to be under src
folder
package.json
, add the start script as index.js
or app.js
based on your script"start": "node src/index.js",
[config] project = api
Yes, the way you specified is correct to deploy a subfolder.
Cannot find module '../package.json
Remove the node_modules
folder and package-lock.json
and run npm install
again
Upvotes: 0