简体   繁体   中英

Unable to use imported SASS styles in my React js project

I have followed the same process I use in most of my projects for importing SASS styles. I created my react app app. Installed SASS with the following command npm install node-sass I import my SASS file into my app components as shown below:

import React from "react";
import { ProvideAuth, useAuth } from "./use-auth.js";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import './test.scss';

function App() {
  const auth = useAuth();

  return (
    <ProvideAuth>
      <Router>
        <nav>
          <div>
              <Link to='/'>Home</Link>
              <Link to='/about'>About</Link>
          </div>
          <div>
              <button onClick={() => auth.signin()}>Sign In</button>
              <button onClick={() => auth.signout()}>Sign Out</button>
          </div>  
        </nav>

        <Switch>
          <Route exact path="/">
            home
          </Route>
          <Route path="/about">
            about
          </Route>
        </Switch>

      </Router>
    </ProvideAuth>
  );
}

export default App;

This SASS file 'test.scss' is kept within the same folder as App.js I have kept the contents of this SASS file very basic for the sake of testing:

nav{
    display: flex;
    background: blue;
}

The project compiles without any errors yet none of my styles are applied. Below is the package.json for my project:

{
  "name": "wally",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "firebase": "^8.7.1",
    "node-sass": "^6.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^1.1.5",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "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"
    ]
  }
}

Okay I have no real answer to my own question but effectively I rebuilt the project and things seemed to work fine. Effectively turning it off and on again.

I viewed some other similar questions and some people had issues integrating sass with react-router. Not too sure if that's related to my particular issue, nonetheless reinstalling everything from new seemed to solve things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM