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
330 stars 57 forks source link

Can't deploy Next.js SSR app #1255

Open wojtekmaj opened 1 year ago

wojtekmaj commented 1 year ago

Describe the bug

I can't for the life of me figure out how to deploy Next.js SSR app. Tried every possible combination, with standalone output or not:

      #- script: yarn build
      #  displayName: 'Build'

      - task: AzureStaticWebApp@0
        displayName: 'Deploy to Azure Static Web Apps'
        inputs:
          azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
          app_location: '/'
          api_location: ''
          output_location: ''
          app_build_command: yarn build && npm pkg set packageManager=yarn@3.6.0
        env:
          PRE_BUILD_COMMAND: corepack enable

Not only this uses Yarn 3 for build and Yarn 1 for deploy parts (completely fails to detect .yarnrc.yml which is supposed to detect modern version of Yarn), but ends up with an error:

The content server has rejected the request with: BadRequest
Reason: The size of the function content was too large. The limit for this Static Web App is 104857600 bytes.

Tried this with custom build:

      - script: yarn build
        displayName: 'Build'

      - task: AzureStaticWebApp@0
        displayName: 'Deploy to Azure Static Web Apps'
        inputs:
          azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
          skip_app_build: true
          app_location: ''
          output_location: ''

and:

      - script: yarn build
        displayName: 'Build'

      - task: AzureStaticWebApp@0
        displayName: 'Deploy to Azure Static Web Apps'
        inputs:
          azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
          skip_app_build: true
          app_location: '.next'
          output_location: ''

and also:

      - script: yarn build
        displayName: 'Build'

      - task: AzureStaticWebApp@0
        displayName: 'Deploy to Azure Static Web Apps'
        inputs:
          azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
          skip_app_build: true
          app_location: '.next/standalone'
          output_location: ''

and got:

App Directory Location: '.next' is invalid. Could not detect this directory. Please verify your deployment configuration file reflects your repository structure.

or:

Failed to find a default file in the app artifacts folder (.next). Valid default files: index.html,Index.html.
If your application contains purely static content, please verify that the variable 'app_location' in your deployment configuration file points to the root of your application.
If your application requires build steps, please validate that a default file exists in the build output directory.

Expected behavior

Next.js application to deploy

Device info (if applicable):

jakepears commented 1 year ago

try 'npx vercel' deploy if ur trying to deploy there. otherwise if you're using something like netlify, you could try just connecting the github repo to the project.

it seems like it's saying that you're basically doing too much at once, you could try swapping to npm, code-splitting, or install @next/bundle-analyzer the running 'ANALYZE=true yarn build' that should help determine an exact cause a bit easier. also 'yarn lint' can be a good tool.