firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.97k stars 916 forks source link

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html" #7402

Closed luiztux closed 2 days ago

luiztux commented 3 days ago

[REQUIRED] Environment info

firebase-tools: 13.12.0

Platform: Windows

[REQUIRED] Test case

This is a react app. I'm using vite and pnpm. Build my app: pnpm run build Then: firebase deploy --only hosting

My firebase.json:

"hosting": {
    "site": "myhostingwebsite",
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },

I am using firebase emulators as well.

[REQUIRED] Steps to reproduce

After build for production, just run the command firebase deploy --only hosting

[REQUIRED] Expected behavior

The website should appear correctly

[REQUIRED] Actual behavior

I get an error in the console: 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.

luiztux commented 3 days ago

Forgot to mention Frank's answer on StackOverflow: https://stackoverflow.com/a/78674896/25876657

aalej commented 2 days ago

Hey @luiztux, sorry to hear that you encountered this issue, and thanks for reaching out. I’m currently working on replicating this issue, but so far I haven’t been able to reproduce the same behavior.

From what I can gather based on the steps you provided, your project would look like this. Let me know if I missed anything or made a mistake in the setup. Alternatively, any chance you could share a minimal reproducible example example with us? This will help us to accurately reproduce the issue.

Also, could you share your firebase-debug.log so that we can check if there were any issues during deployment? Please remove any personal identifiable information(PII) before sharing the contents of the file.

luiztux commented 2 days ago

Hi @aalej , thank you for your response. Windows drives me crazy. I honestly have no idea why it didn't work yesterday, even after restarting the system (after updating firebase-tools) the problem continued. Today, after turning on Windows, I deployed a very simple website (react+vite) and it worked. Then I deployed the real application and it is working correctly. OMG.