Working on a Nuxt 3 SSR application deployed to Azure DevOps + Web App through pipeline and running into the following console error message for every pre-rendered static .js route under /public/_nuxt/.
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
The error originates in my /public/index.html entry-point on several lines that look like:
<link rel="modulepreload" as="script" crossorigin href="/_nuxt/useExample.37a37e6a.js">
I've tried fiddling with the web.config and nuxt.config.ts which hasn't done much but go one step backwards. Why would my routes either not be resolving correctly or if that isn't the issue, why wouldn't the "text/html" error be fixed by my nitro setting?
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="public/index.html" />
</files>
</defaultDocument>
<directoryBrowse enabled="true" />
<rewrite>
<rules>
<rule name="Handle History Mode and custom routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".mjs" mimeType="application/javascript" />
<mimeMap fileExtension=".js" mimeType="application/javascript;" />
</staticContent>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="public/404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
nuxt.config.ts:
export default defineNuxtConfig({
...
nitro: {
publicAssets: ['/_nuxt/**/*'],
},
ssr: true,
...
});
azure-pipeline.yml:
trigger:
- sandbox
pool:
vmImage: ubuntu-latest
stages:
- stage: Build
jobs:
- job: BuildAndPackage
steps:
- task: NodeTool@0
displayName: Install Node.js
inputs:
versionSpec: '18.x'
- task: Npm@1
displayName: Install Dependencies
inputs:
command: 'ci'
- script: npm run build
displayName: Build Nuxt App
- script: npm run generate
displayName: Generate Static Nuxt App
- task: CopyFiles@2
displayName: Copy Nuxt Output
inputs:
SourceFolder: '.output'
Contents: '**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)/nuxt-output'
- task: CopyFiles@2
displayName: Copy essential files to root
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
package.json
nuxt.config.ts
tsconfig.json
web.config
TargetFolder: '$(Build.ArtifactStagingDirectory)/nuxt-output'
- task: PublishBuildArtifacts@1
displayName: Publish Nuxt Output Artifact
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/nuxt-output'
ArtifactName: nuxt-output
- stage: Deploy
displayName: Deploy to Azure Web App
dependsOn: Build
jobs:
- job: Deploy
displayName: Deploy Nuxt 3 application
steps:
- task: DownloadBuildArtifacts@0
displayName: Download Nuxt Output Artifact
inputs:
artifactName: nuxt-output
downloadPath: '$(Build.ArtifactStagingDirectory)/nuxt-output'
- task: AzureWebApp@1
displayName: 'Deploy to Azure Web App'
inputs:
azureSubscription: 'zzz'
appType: 'webApp'
appName: 'zzzz'
slotName: 'zzzzz'
package: '$(Build.ArtifactStagingDirectory)/nuxt-output/*'
- Node: ~18
- NPM: >= 7
- Nuxt: 3.7.3
- Azure Web App w/ Windows
- Azure DevOps w/ Pipeline
Also found this GitHub issue that could be related - https://github.com/nuxt/nuxt/issues/19752


modulepreloadlinks are correct and that the JavaScript files are actually being served at those URLs. You can check this by trying to access the URLs directly in your browser or using a tool likecurl.Make sure that the JavaScript files are being served with the correct MIME type (application/javascript). You can check this using the browser's network tab. check JavaScript files and the "Content-Type" header in the response.application/javascript. My guess would be somewhere in my web.config file.<staticContent> <remove fileExtension=".js" /> <mimeMap fileExtension=".js" mimeType="application/javascript" /> </staticContent>clear browser cache and try again to access the site