0

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"
    ]
  }
}

1
  • Are you sure that you used it just like this in other projects? Looking at node-sass it seems that you need to do something like var sass = require('node-sass'); and then sass.render ({file:'test.scss'}). But I'am not sure about reactjs in this context. Commented Jul 22, 2021 at 11:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

If you're just starting, it is preferred to use 'sass' package (formerly dart-sass) instead of 'node-sass' these days.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.