Css not loading/working

Am using Node js React and vite as the build tool. The project has two folders a client and server folder. The server folder is hosted in render.com and client is hosted on netlify. Here is the link

initially, I keep getting this error :

/src/main.jsx:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “application/octet-stream”. Strict MIME type checking is enforced for module scripts per HTML spec.

then I solved it by going through the netlify support,but the CSS(Tailwindcss) is not working/loading now.
the page is only loading the raw HTML,

can someone check the page https://booktheticket.netlify.app/ and help he to solve the issue

when I run the npm run build locally in my Vs Code and open the index.html inside the dist with live server it is working fine all the css/tailwindcss is loading the page is working fine but the CSS/tailwind is not loading/working when deployed in netlify.

This issue would have been because you were accidentally deploying the source code.

The CSS file that the page includes is loading.

It just may not contain whatever you expect it to contain.

Your deployed HTML is:

Both the js and css file exist and are loading (which you can confirm by visiting their URL’s):
https://booktheticket.netlify.app/assets/index-Do9QUNnV.js
https://booktheticket.netlify.app/assets/style-B6SO5eZs.css

If the contents of the CSS file appear wrong, and you’re seeing a difference between “development” and “build” it could be that your “build” doesn’t operate with the same configuration as your “develop” command.

Vite has a “preview” command you can use to check your build output locally.
https://vite.dev/guide/cli#vite-preview

Run npm run build && npm run preview.

Running that command locally should confirm the issue is actually unrelated to Netlify.

but when I open the index.html inside the dist with live server it is working fine which means it contains the CSS as I expect…after npm run build

@markIB What precisely do you mean by “live server”?

I’m concerned you might be “running the build” then “running the dev server”, and that you think that means your “build” has worked ok.

Only the command that I wrote shows you the result of the “build”.

If you run the “dev” command, then you’re looking at the “dev” server output, which quite frequently with Vite doesn’t result in the same thing as the “build”.

Did you run npm run build && npm run preview?
If so, what did you see?

yes…

@markIB I don’t use whatever IDE you’re using, so I have absolutely no idea what that is.

I just run the scripts that Vite provides in the package.json or its own commands.
Which tend to be these:

When you run npm run build && npm run preview does it show what address to visit in your browser?

When you visit the address in your browser does your site load correctly?

This is what it should show:

(That’s just a blank project I created with npm create vite@latest - to demonstrate what the npm run build && npm run preview command should do)

If you’re having difficulty with Vite’s preview server, you could try serving your build output withnpx serve (https://www.npmjs.com/package/serve).

It doesn’t really matter what you use, the main point is just to “actually be looking at the result of your build” so you can confirm the issue is being caused by the build (not something in the CI environment / host).

In your screenshot your preview tries to run react-env --env env --vite preview
But then immediately dies because it doesn’t know what to do for react-env

this is in the http://localhost:5173:

And in https://67dbba5954c718f34ca2929a--booktheticket.netlify.app its still like:

@markIB Do you have a link to a public repository?

Also I just noticed…

In this screenshot:
https://answers.netlify.com/t/css-not-loading-working/142486/8

It has localhost:4173, that’s what you need to view.

In this screenshot:
https://answers.netlify.com/t/css-not-loading-working/142486/9

You’ve indicated you are looking at localhost:5173
(I can’t tell what you were actually looking at, as you didn’t include it in the screenshot.)

Is it possible you’re getting confused?
Perhaps starting the ‘preview server’, but then accidentally looking at the ‘dev server’ (which you still have running)?

@markIB It does in fact work perfectly fine for me:

So I’d expect it to also work on Netlify.
Provided the build configuration is running the build & deploying the correct files.

The CSS that I see it generate locally, and the CSS on Netlify is identical.
Both have the same hash of B6SO5eZs.

@markIB Something strange I’m seeing…

Your stylesheet is being served with a Content-Type of application/javascript

Are you aware of anything you’ve done that would be causing that?

No.. i dont have any idea on that

can you please suggest me the way to fix that…

@markIB Unfortunately I cannot, as I’m not sure what’s going on.

I’m going to keep playing around out of my own interest, but you may have to wait for Netlify’s support team (I don’t work for them).

Ok, I’ve spotted it.

Run npm run build then take a look in the dist folder that it produces.

You’ll find there is a _headers file which contains:

/assets/*
  Content-Type: application/javascript

… don’t do that.

It’s only broken on Netlify, because the _headers file is only being used on Netlify.

You should remove it from your public folder, so it’s no longer output into dist.

should i delete the _headers file inside the public folder or just remove the content of _headers file?

You can do either, since it’s your project and your choice.

They’ll both “fix your site”.

You can leave it there if you think you will want to add custom _headers in future.

You should obviously be wary of that though if you don’t understand them.
Since you can cause issues precisely like you have here.