MIME type Error in Web Browser for Angular using Firebase

Discussão em 'Angular' iniciado por WillKro, Dezembro 5, 2024.

  1. WillKro

    WillKro Guest

    For a while now, anytime I make a push to my application, I will usually run into this error: "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."

    Whenever I create a build using "ng build --configuration production", I get this directory for my build: "dist/browser/assets".

    dist has nothing but a 3rdpartlicenses.txt file, but browser has all the packets and contents of the build.

    I've been doing a lot of research on this issue, but no one seems to have a definitive answer that isn't deprecated. Has anyone else that uses Angular run into this issue before? Any help would be greatly appreciated, thanks.

    P.S. I am running Angular 17

    angular.json:

    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
    "chime-in": {
    "projectType": "application",
    "schematics": {},
    "root": "",
    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:application",
    "options": {
    "outputPath": "dist",
    "index": "src/index.html",
    "browser": "src/main.ts",
    "polyfills": [
    "zone.js"
    ],
    "tsConfig": "tsconfig.app.json",
    "assets": [
    "src/favicon.ico",
    "src/assets",
    "src/icons"
    ],
    "styles": [
    "node_modules/@ngneat/hot-toast/src/styles/styles.css",
    "@angular/material/prebuilt-themes/indigo-pink.css",
    "src/styles.css"
    ],
    "scripts": []
    },
    "configurations": {
    "production": {
    "budgets": [
    {
    "type": "initial",
    "maximumWarning": "1mb",
    "maximumError": "1.5mb"
    },
    {
    "type": "anyComponentStyle",
    "maximumWarning": "2kb",
    "maximumError": "4kb"
    }
    ],
    "outputHashing": "all",
    "baseHref": "/",
    "deployUrl": "/"
    },
    "development": {
    "optimization": false,
    "extractLicenses": false,
    "sourceMap": true,
    "namedChunks": true
    }
    },
    "defaultConfiguration": "production"
    },
    "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "configurations": {
    "production": {
    "buildTarget": "chime-in:build:production"
    },
    "development": {
    "buildTarget": "chime-in:build:development"
    }
    },
    "defaultConfiguration": "development"
    },
    "extract-i18n": {
    "builder": "@angular-devkit/build-angular:extract-i18n",
    "options": {
    "buildTarget": "chime-in:build"
    }
    },
    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "polyfills": [
    "zone.js",
    "zone.js/testing"
    ],
    "tsConfig": "tsconfig.spec.json",
    "assets": [
    "src/favicon.ico",
    "src/assets",
    "src/icons"
    ],
    "styles": [
    "@angular/material/prebuilt-themes/indigo-pink.css",
    "src/styles.css"
    ],
    "scripts": []
    }
    }
    }
    }
    }
    }


    firebase.json:

    {
    "functions": [
    {
    "source": "functions",
    "codebase": "default",
    "ignore": [
    "node_modules",
    ".git",
    "firebase-debug.log",
    "firebase-debug.*.log",
    "*.local"
    ],
    "predeploy": [
    "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
    }
    ],
    "hosting": {
    "public": "dist",
    "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
    ],
    "rewrites": [
    {
    "source": "**",
    "destination": "/index.html"
    }
    ],
    "headers": [
    {
    "source": "/index.html",
    "headers": [
    {
    "key": "Cache-Control",
    "value": "no-cache, no-store, must-revalidate"
    }
    ]
    },
    {
    "source": "/**/*.@(js|css|html)",
    "headers": [
    {
    "key": "Cache-Control",
    "value": "max-age=31536000"
    }
    ]
    },
    {
    "source": "/**/*.js",
    "headers": [
    {
    "key": "Content-Type",
    "value": "application/javascript"
    }
    ]
    }
    ]
    }
    }


    index.html:

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>ChimeIn</title>
    <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    </head>
    <body class="mat-typography">
    <app-root></app-root>
    </body>
    </html>

    Continue reading...

Compartilhe esta Página