Azure / Azure/static-web-apps

Next.js Hybrid - All Static Resources are Refused to Apply Causing the App to not render

Open
#1,620 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

We are experiencing an issue with our Next.js 14 hybrid application running on Node 18.17 deployed to Azure Static Web Apps (SWA). The build appears to be successful, and the files are deployed to SWA. However, when loading the application, all the static resources (CSS, chunks, images) are refused to apply.

**Details:**
- Next.js Version: 14
- Node Version: 18.17
- Deployment Platform: Azure Static Web Apps (SWA)

**To Reproduce**
Steps to reproduce the behavior:
1. Tyring to load the landing page on the application
2. No static elements rendered

All static resources for the app (CSS, chunks, images) are refused to apply. The links look like:

```bash

```
The browser console shows:

```bash
Refused to execute script from '' because its MIME type ('text/html') is not executable
Refused to apply style from '' because its MIME type ('text/html')
```

![Image](https://github.com/user-attachments/assets/02df3da5-b377-4a32-b1a6-19b92bb6177a)

**GitHub build action**

```
app_location: "/app/portal" # App source code path
api_location: "" #/app/portal/api Api source code path - optional
output_location: "/.next/server/app" # Built app content directory - optional
```
> Deployment works

**staticwebapp.config.json**
> Partial
```
{
"route": "/_next/static/*",
"allowedRoles": ["anonymous"]
},
{
"route": "/",
"allowedRoles": ["anonymous"]
},
{
"route": "/public",
"allowedRoles": ["anonymous"]
},

"navigationFallback": {
"rewrite": "/index.html",
"exclude": [
"/images/*.{png,jpg,gif}",
"/_next/*",
"/css/*",
"/js/*",
"/fonts/*"]
},

"mimeTypes": {
".html": "text/html",
".json": "application/json",
".css" : "text/css",
".js": "text/javascript",
".woff2": "font/woff2",
}

```

**Expected behavior**
The landing page should rendered properly with all the /_next/* resources loading with HTTP 200 status

**Device info (if applicable):**
- Browser [e.g. chrome, safari]
- Version [e.g. 133]

**Additional context**

Reference: https://learn.microsoft.com/en-us/azure/static-web-apps/deploy-nextjs-hybrid

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.