Hey Replit community!
While trying to dynamically open a page and display some data I fetched from Node.js server, I’ve got an error in the console Refused to execute script from 'https://.../js/act.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. In total I have 2 pages which fetch the data from server and display it in browser. With the first page (account.js) I have no problems, it works perfectly, but after connecting second page (which works the same way - gets server’s data and displays it) I’ve discovered this error. First page still works fine but the second doesn’t.
Repl: https://replit.com/@entcode/ejs?v=1
Also, the console shows an 404 error ‘act.js’ not found, however such file is presented and its directory is used via app.use(). Here are the screenshots:
When I include the contents of the script file into EJS file (pure <script></script> tags without src attribute specified), everything works fine. May it be a bug of Replit that doesn’t see the file?
This will cause a problem because if you try to access /js/act.js , it’s going to match the /:user_email_id route, treating “js” as a user_email_id , hence the 404 error since it won’t find a corresponding user in the dbase object.
So the solution is to you rearrange your routes to ensure that static files are served before dynamic routes and fix the paths to the static files.
Hey @WindLother ! Thanks for your response! I’ve tried rearranging the routes, but nothing dramatically changed. I still get the same two errors: 404 file not found and wrong MIME type. Could you check my Repl (https://replit.com/@entcode/ejs?v=1) again, please?
Thanks!
Hello @WindLother ! I want to develop a website as a school project (for public use). As I understand, clearing the cache will solve the problem just for me, so other users may get the same errors. Am I right or this is a universal solution?
Thanks!
I followed your recommendation, @WindLother and cleared the browser’s cache and tried opening the webpage in private window, but nothing worked :"( Looks like there is an error in the code itself
Hey @WindLother ! I’m thinking, may it be just a bug of Replit? I’ve tried like every possible solution on stackoverflow, chatbot ai, etc but nothing worked. Should I report it?
Well, I’ve figured out what was the problem. I don’t know why, but the absence of this tiny slash (pic attached) jammed the path to .js file and so browser was throwing 404 error. Now everything works fine. Anyway, thanks a lot for your time!