azuregithubcontinuous-deploymentazure-static-web-app

Azure Static Web App deploying via GitHub Actions (.yml) errors with 404 on private npm packages


I have an Angular app in GitHub that is deploying to an Azure Static Web App via GitHub actions.

The deploy fails when I add a private npm package.

In GitHub Docs I found how to specify an npm token for a node script via environment setting, and have combined this with Azure's docs on customizing the workflow file, which led me to try this (and a few variations of it):

  - name: Build And Deploy
    id: builddeploy
    uses: Azure/static-web-apps-deploy@v1
    with:
      azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_RANDOM }}
      repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
      action: "upload"
      ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
      # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
      app_location: "/" # App source code path
      api_location: "" # Api source code path - optional
      output_location: "dist" # Built app content directory - optional
      ###### End of Repository/Build Configurations ######
    env:
      NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

The last line with NODE_AUTH_TOKEN I had read would generate an .npmrc file that would authenticate the process. I have a GitHub secret called NPM_TOKEN containing a token I generated in npm, selecting the 'for CI purposes' option.

But I am still seeing the 404 error when attempting to install the private package.

Any ideas would be appreciated!


Solution

  • Found this post on medium: Install private NPM packages in github actions

    Following the advice there I "manually" created the .npmrc file before calling the azure deploy action and that solved it:

          - name: Create .npmrc file
            run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
          - name: Build And Deploy
            id: builddeploy
            uses: Azure/static-web-apps-deploy@v1
            .......