package.json issue while deploying a node api on Azure App Service

Miaourt 6 Reputation points
2022-08-17T08:01:12.317+00:00

Hello everyone.

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.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,408 questions
{count} votes