Dealing with undefined variables when importing into create-react-app Sass: SassError

I am using create-react-app with SCSS style-files. My project includes an App.scss file where I import all other .scss stylesheets, and a variables.scss file where I define all project variables.

However, when I import variables.scss into App.scss and then import all component style-files, I encounter an error

SassError: Undefined variable: $grey
, which is being used in border-bottom: 1px solid $grey in the Header.scss file.

While importing variables.scss directly into Header.scss resolves the error and everything works fine, I do not want to include variables in every component .scss file.

How can I effectively utilize variables from variables.scss across all files in my project?

My attempts so far:

  • Renaming variables.scss to _variables.scss and importing as @import 'components/variables';
  • Importing variables.scss before other imports in App.scss
  • Directly importing variables.scss into index.scss
  • Searching for a solution but nothing has worked so far

variables.scss

$grey: #fefefe;
$black: #000000;

App.scss

@import 'components/variables';
@import 'components/header/Header.scss';

Project Structure Screenshot

Answer №1

It appears I have discovered the solution to the issue.

Instead of just importing SASS-files into App.scss, I also imported them into relative component .js-files. As a result, the problem was resolved when I eliminated import './Header.scss' from the Header.js file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to displaying API response data in a React JS application

As a beginner in react JS, I've encountered a persistent issue. Here is the code: import React from 'react'; class SearchForm extends React.Component { async handleSubmit(event){ event.preventDefault(); try{ const url ='/jobs/ ...

Error: Unable to locate 'ipfs-http-client' module in 'D:Prosrccomponents' directory

I have been experiencing some issues while trying to send files to IPFS using a website built in Node.js. My code includes the ipfs-http-client module, but whenever I try to access it using 'require', I encounter the following error: Module not ...

Resize an image to fit perfectly within a material-ui grid

Is there a way to resize images within a grid layout without them getting cropped? Each image I try to fit into the top horizontal grid behaves differently due to varying dimensions. Instead of stretching and fitting into the container, the images end up b ...

What is the best way to arrange map elements in a React application?

I am trying to implement filter buttons for low to high rates and high to low rates, but I am having trouble figuring it out. How can I apply the filter to display the data accordingly? The data that needs to be filtered is stored in rate.retail_rate. ty ...

Having difficulty importing an ES2015 module

As I work on creating my own npm library, I encountered an issue when trying to integrate it into another application. For example: import React from 'react'; import SmallGrid from 'react-smallgrid'; export default class Library exte ...

Is there a way to have an HTML scrollbar automatically start at the bottom?

I'm having trouble ensuring that my chatbox's scrollbar automatically starts at the bottom so that new messages are visible without needing to scroll down. The current code I have in JQuery is not achieving this desired behavior. $('#chatbo ...

Having trouble aligning material-ui GridList in the center

I am currently working with a GridList in order to display Cards. The styling for these components is set up as shown below: card.js const useStyles = makeStyles({ card: { maxWidth: 240, margin: 10 }, media: { heigh ...

Tips for managing onChange events in TypeScript

I'm still learning Typescript and I have a question regarding handling the onChange event in a TextField component when using Typescript. Can you provide guidance on how to approach this? I currently have a function called handleChangeDate(e: React. ...

"Incorporate Bootstrap drop-down and button together for a stylish group feature

I am looking to format the code below to resemble the layout shown in the image using Bootstrap 3.3. When there isn't enough space to show all elements in a single line, I want them to stack vertically so that each element utilizes the entire width of ...

React component combined with Material-UI library generates a warning message: Prop className does not match

Struggling with different styles between client-side and server-side rendering in Material-UI components due to inconsistencies in classNames assignment. Initially, the classNames are assigned correctly upon loading the page. However, upon refreshing the ...

Preventing State Synchronization in JHipster React Project between Browser Tabs

It seems like the topic revolves around react-redux but I don't have much experience with it. I created a Monolithic jhipster-react project with ehcache and h2 database for development purposes. After running it with ./mvnw and then npm start, I not ...

Another option to innerTheme for customizing primaryTypographyProps in a unique way

I have a unique component with customized list items, icons, and buttons. I need to use this component in two different locations. In the first location, I adjusted the MuiListItemTextTypography props like this... const mainTheme = createMuiTheme({ . . . ...

Express JS backend causing CSS file to fail to load in React project

After doing some research on Stack Overflow, I came across a few solutions but none of them seemed to work for my specific situation. I am currently attempting to serve my React website from an Express backend server. Here is the layout of my folders: cli ...

Can anyone assist with troubleshooting the font size issue for a JavaScript tooltip on Joomla 1.5 with CK Forms?

My Joomla 1.5 site has CK Forms installed and is functioning properly, except for one issue: the tooltip on the captcha is not displaying correctly. It appears in a tiny 1px font size. Even though I have tried debugging using Firebug and confirmed that the ...

Tips for addressing the ESLint issue stating that the package should be included in dependencies instead of devDependencies

Struggling to properly lint my React+Typescript project with ESLint. In one of my components, I'm utilizing the useParams hook from react-router. import { useParams } from 'react-router'; However, ESLint is throwing an error on that line: E ...

Encountering an Uncaught TypeError when attempting to read properties of undefined, specifically 'backdrop', while incorporating a bootstrap 5 modal within a react environment

An issue occurred when attempting to display a Bootstrap 5 modal using JavaScript. const handleClick = (e) => { e.preventDefault(); const modalElement = document.getElementById('editUserModal'); const modal = Modal.getOrCreateInsta ...

Is there a space added after applying overflow:hidden to a div?

.d1 { height: 10px; } .dd { display: inline-block; overflow: hidden; } .dd1 { display: inline-block; } <div class="d1"> <div class="dd"></div> <div class="dd1"></div> </div> To adjust the layout so that th ...

How to troubleshoot when Reactjs doesn't render anything after successfully posting a new note using axios to the server?

I am currently working on updating data in the backend using a json server. I've noticed that when I refresh the server, the new data gets posted successfully; however, the render of the updated list disappears from the screen after submitting. Can an ...

Steps to include a title next to a progress bar:

Is there a way to achieve something like this? https://i.sstatic.net/dhO2f.jpg I attempted to use bootstrap but I ran into an issue where the title was slightly misaligned below the progress bar. Can someone offer assistance with this matter? Apologies i ...

What steps should I take to correct the alignment of this grid using CSS?

I'm currently working on creating a grid layout for my website and I've almost achieved the desired result. However, I'm facing an issue with the size of the "Projects" title within the grid. I want it to stand out and be larger compared to ...