I got this error on my website pages. Here on localhost everything is fine, but when I put it in production this error appears in the console. The site is made in html/css, javascript (without framework) and with astro. It is hosted on cloudflare pages.
“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.”
Quite possibly this is due to a 404 Not Found error. Have you checked the path for the asset to ensure it is correct?
Can you share a URL?
yeah, this started happening after I created the 404.astro folder.
the url is acalculator.com.br
Here on localhost the pages work normally, but when I put them online, both the css and the js break.
looking in inspect, a strange thing happens. The css is imported as module-type scripts.
So the CSS and JS imports generated by Astro are not working.
Does it also work locally when you run npm run build
and browse the built site?
To test
- Delete current build output directory
- Build site (e.g.
npm run build
)
- Serve
npx serve <build-output-path>
Then browse this site on localhost:3000
to see if it works.
bro, I’m using the translator.
Yes, it worked here locally and when I went up it wasn’t working like in the production environment.
This all started happening this afternoon when I changed a url and tried to make a code to redirect the old url to the current one.
Then I even tried to make a script for the 404 error. Just now I discovered that the errors were precisely in those changes that I made. Mainly in the astro.config.mjs root file.
Then I deleted the changes I made to that file (redirect changes) and left it original. The redirection is now being done only for 404 errors. The redirection from the old url to the current one, I haven’t been able to implement it yet.
So far the pages are working equally on localhost and online.
The 404.star looked like this
astro:
metadata:
status: 404
Redirecionando...
Se você não foi redirecionado automaticamente, clique
aqui.
thanks, bro