Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
318 stars 53 forks source link

Deploying nextjs app with pnpm causes `Webapp warmup timeout` #1457

Closed brianmgray closed 1 month ago

brianmgray commented 2 months ago

Description I have a Github Actions workflow that has been successfully deploying my nextjs app using npm to Azure Static Webapps for a few weeks. I migrated to pnpm for improved dependency management- it was a few lines of code to change. This builds fine locally, but on Github, the build consistently fails with this message:

Finished Upload. Polling on deployment.
Status: InProgress. Time: 0.0557385(s)
....
Status: InProgress. Time: 574.5292073(s)
Status: Failed. Time: 589.5829263(s)
Deployment Failed :(
Deployment Failure Reason: Web app warm up timed out. Please try again later.

Note: typically before this change this check would take about 20 seconds before I get a valid response from the app and the build completes.

To Reproduce

Here are the key files involved (I can't link directly to source, private repo).

# pr.yml
name: Build and deploy (PR)

on:
  pull_request:
    types: [opened, synchronize, reopened]
    branches:
      - main
  workflow_dispatch:

jobs:
  exec:
    uses: ./.github/workflows/build-and-deploy.yml
    secrets: inherit
    with:
      preview: true
# build-and-deploy.yml
name: Build and deploy
...
jobs:
  build_and_deploy:
    name: Build and Deploy
    runs-on: ubuntu-latest
    ...
    steps:
      ...
      - name: Use pnpm ${{ env.PNPM_VERSION }}
        uses: pnpm/action-setup@v3
        with:
          version: ${{ env.PNPM_VERSION }}
      - name: Use Node.js ${{ env.NODE_VERSION }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
      - name: Install
        run: |
          # force a development install, to make sure dev dependencies are installed
          # they get filtered out by the standalone build for next
          NODE_ENV=development pnpm install

      - name: Build
        run: pnpm run build

      - name: Test
        run: pnpm run test

      - name: Deploy
        id: deploy
        if: ${{ !env.ACT || env.DEPLOY == 'true' }}
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          skip_app_build: true
          skip_api_build: true
          app_location: ${{ env.APP_LOCATION }}
        env:
          skip_deploy_on_missing_secrets: true

Expected behavior Deployment would succeed and I would be able to access the static web app at the preview URL provided by the build.

Screenshots n/a

Device info (if applicable): n/a

Additional context Not sure what else would help, let me know!

petero-dk commented 1 month ago

This was a problem for me to, it was based on node_modules not being in the right place or symlinked.

For me it was important to to the following in the .npmrc

shared-workspace-lockfile=false
node-linker=hoisted

which means NO SYMLINKS, but also keep a full node_modules in each project in the shared workspace. If I hoisted the modules to the shared workspace then it would fail with that exact error.

However beware, using this configuration you might run into this problem: https://github.com/pnpm/pnpm/issues/6584

bbehling commented 1 month ago

Same issue here, but intermittent.

brianmgray commented 1 month ago

Thanks @petero-dk , I will give this a try in the near future.

brianmgray commented 1 month ago

Yeah @petero-dk , this resolved the issue for me too. Thanks so much!