0

So I have a reactjs project with typescript including scss, javascript is working perfeclty fine but page is loading without CSS.

my package.json file:

{
  "name": "qb-front",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/core": "^7.20.12",
    "@mui/icons-material": "^5.11.0",
    "@mui/material": "^5.11.3",
    "@reduxjs/toolkit": "^1.8.3",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^14.2.3",
    "@types/jest": "^27.5.2",
    "@types/node": "^17.0.45",
    "@types/react": "^18.0.15",
    "@types/react-dom": "^18.0.6",
    "@types/react-redux": "^7.1.24",
    "@types/redux-saga": "^0.10.5",
    "axios": "^0.27.2",
    "bootstrap": "^5.2.0",
    "formik": "^2.2.9",
    "jquery": "^3.6.0",
    "jwt-decode": "^3.1.2",
    "moment": "^2.29.4",
    "node-forge": ">=1.3.0",
    "popper.js": "^1.16.1",
    "react": "^18.2.0",
    "react-bootstrap": "^2.5.0",
    "react-dom": "^18.2.0",
    "react-hot-toast": "^2.3.0",
    "react-icons": "^4.4.0",
    "react-player": "^2.11.0",
    "react-redux": "^8.0.2",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "react-select": "^5.4.0",
    "reactstrap": "^9.1.1",
    "redux": "^4.2.0",
    "redux-saga": "^1.1.3",
    "sass": "^1.57.1",
    "typescript": "^4.7.4",
    "web-vitals": "^2.1.4",
    "yup": "^0.32.11"
  },
  "scripts": {
    "start": "react-scripts start tsc --watch",
    "build": "GENERATE_SOURCEMAP=false PUBLIC_URL=/ react-scripts build",
    "winBuild": "set \"GENERATE_SOURCEMAP=false\" &&  react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
    "lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'",
    "format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
    "dev": "tsc --watch"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/jquery": "^3.5.14",
    "@types/prettier": "^2.7.2",
    "@typescript-eslint/eslint-plugin": "^5.30.5",
    "@typescript-eslint/parser": "^5.30.5",
    "eslint": "^8.19.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-prettier": "8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-jsx-a11y": "^6.6.0",
    "eslint-plugin-prettier": "4.2.1",
    "eslint-plugin-react": "^7.30.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "prettier": "^2.8.2"
  }
}

Localhost with npm start works perfectly fine, but when i build, css are gone.

Here is a screnshot from network:

network

Extra infos:

  • project is running nginx and docker on a server node-16
  • sass installed as normal dependency
  • project has mui - bootstrap - scss

app.scss

file structure: App.js has app.scss imported. app.scss has imported variables.scss from assets folder.

There are no errors in terminal, server and docker logs, and this is the only output for sass.


LOG from ./node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js sass-loader ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[7].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[7].use[2]!./node_modules/resolve-url-loader/index.js??ruleSet[1].rules[1].oneOf[7].use[3]!./node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[7].use[4]!./src/App.scss
<w> Deprecation $weight: Passing a number without unit % (100) is deprecated.
<w>
<w> To preserve current behavior: $weight * 1%
<w>
<w> More info: https://sass-lang.com/d/function-units
<w>
<w> node_modules\bootstrap\scss\_functions.scss 201:11            opaque()
<w> node_modules\bootstrap\scss\mixins\_table-variants.scss 4:28  table-variant()
<w> node_modules\bootstrap\scss\_tables.scss 147:3                @import
<w> node_modules\bootstrap\scss\bootstrap.scss 20:9               @import
<w> src\App.scss 1:9                                              root stylesheet
<w>

Update: new error that I occurred in mozzila firefox, I was using chrome/brave:

Layout was forced before the page was fully loaded. If stylesheets are not yet loaded this may cause a flash of unstyled content. node.js:396
The stylesheet /static/css/main.c4cbb89d.css was not loaded because its MIME type, “text/plain”, is not “text/css”.

im trying to use scss but it seems react is failing to compile.

  • what does your webpack config look like? can you show your entire package.json? – rolling_codes Jan 14 '23 at 16:43
  • i didnt use npm run eject, so it doesnt have webpack config file, or I don't know that I should use one or not even if I don't use npm run eject. I updated question with package.json file. – Baran Öden Jan 14 '23 at 16:45
  • can you also provide the build error output? – rolling_codes Jan 14 '23 at 16:49
  • it doesnt have any kind of error in terminal, docker logs and server as well. Only output for scss is in development mode which I'm going to put into question aswell because it is a little bit long. – Baran Öden Jan 14 '23 at 16:53
  • 1
    Check your nginx is correctly configured to serve css files. https://stackoverflow.com/questions/10075304/nginx-fails-to-load-css-files#:~:text=The%20mime%20type%20for%20css%20files%20is%20correctly,but%20my%20css%20files%20are%20still%20not%20loaded. – David Jones Jan 14 '23 at 19:20
  • That is worked like charm thank you so much, I forgot to add include mime types line that is totally my bad. – Baran Öden Jan 14 '23 at 20:03
  • @BaranÖden I made the same mistake in my docker containers myself a few months ago. I'm surprised there isn't an nginx image with that preloaded – rolling_codes Jan 23 '23 at 16:00

0 Answers0