# React app - how to import Sass mixin?

**URL:** <https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459>\
**Category:** General\
**Created:** [November 1, 2018, 6:13pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459 "2018-11-01T18:13:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [November 1, 2018, 6:13pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/1 "2018-11-01T18:13:51Z")

</div>

I configured create-react-app to add Sass by following the guide on this link [here](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-css-preprocessor-sass-less-etc), oddly enough when I visit the link I don’t the guide any more.

In any case, everything works smoothly but when I try to run the app with `npm start` I get an error.

 ![37%20PM](https://global.discourse-cdn.com/freecodecamp/original/3X/0/a/0acc7ce5d75aeff09c6e728363b3b8fcfb05789e.png)

This is happening because of a Sass mixin, I had a similar situation when I tried to use a Sass variable so I had to remove it, but in this case I can’t afford to remove the mixin from my files. Does anybody know why is this happening, I can’t see to find any documentation on the issue.

edit: I know now this is happening because the mixin is not importing to all files.

---

<div class="post-metadata">

**Author:** ![Layer](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/layer/32/82898_2.png) [@Layer](https://forum.freecodecamp.org/u/Layer)\
**Post date:** [November 1, 2018, 7:01pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/2 "2018-11-01T19:01:00Z")

</div>

By the way CRA now is augmented : [React blog: CRA 2.0](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html)  
To use sass you only need to install `node-sass` and that’s all, you can directly import `.scss` files into components!

---

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [November 1, 2018, 7:24pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/3 "2018-11-01T19:24:48Z")

</div>

Oh I see, I also found this documentation [here](https://facebook.github.io/create-react-app/docs/adding-a-sass-stylesheet). I already installed Sass, the issue is that whenever I try to run `npm start` it’ll give me an error because it’s not recognizing Sass variables/mixins through all the files.

---

<div class="post-metadata">

**Author:** ![dylanesque](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dylanesque](https://forum.freecodecamp.org/u/dylanesque)\
**Post date:** [November 1, 2018, 7:32pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/4 "2018-11-01T19:32:22Z")

</div>

Which version of create-react-app are you using? IIRC, v2 makes it a lot easier to incorporate sass and similar pre-processors

---

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [November 1, 2018, 8:45pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/5 "2018-11-01T20:45:17Z")

</div>

How can I determine which version I currently have?

---

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [November 1, 2018, 10:16pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/6 "2018-11-01T22:16:22Z")

</div>

Ok I checked and I read how to upgrade to version 2.0, however [here](https://facebook.github.io/create-react-app/docs/adding-a-sass-stylesheet) it says that the command to install Sass is `npm install node-sass --save`, I am not sure if this is the documentation for CRA 2.0. In the link that you sent I couldn’t see anything about how to install Sass.

Another thing, I already installed Sass in my app as per the old version of CRA, so what’s going to happen to that?

---

<div class="post-metadata">

**Author:** ![Layer](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/layer/32/82898_2.png) [@Layer](https://forum.freecodecamp.org/u/Layer)\
**Post date:** [November 2, 2018, 7:09am UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/7 "2018-11-02T07:09:20Z")

</div>

The link i posted is the blog post related to the release of version 2.0, the link you posted is the updated doc 🙂

Anyway there’s no particular needs to update from 1.x to 2.x, it was just a news related to your problem (in your next project you can avoid such config problems^^): to solve your actual issue well, it seems you’re not importing the `.scss` file with the mixin declaration^^

---

<div class="post-metadata">

**Author:** ![Gilbert1391](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gilbert1391/32/93761_2.png) [@Gilbert1391](https://forum.freecodecamp.org/u/Gilbert1391)\
**Post date:** [November 2, 2018, 4:52pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/8 "2018-11-02T16:52:24Z")

</div>

I am importing the file with the mixin declaration. In my index.scss file is where I import all my `.scss` files:

```auto
@import "./styles/base.scss";
@import "./styles/layout.scss";
@import "./styles/components/search-bar.scss";
@import "./styles/components/side-nav.scss";
@import "./styles/components/phone-navigation.scss";
@import "./styles/components/card.scss";
@import "./styles/components/pagination.scss";
@import "./styles/components/dropdown.scss";
@import "./styles/components/dashboard.scss";
@import "./styles/components/cast.scss";

```

The mixin is located in the `base.scss` file. And as I mentioned the import seems to be working because I can see the mixin in the compiled `index.css` file. The issue with the mixin is to start the server, so to get around this I have to comment out the mixin in all my components and run `npm start`, then uncomment them all out again, I can see the changes in the live server, meaning that it’s working.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:54pm UTC](https://forum.freecodecamp.org/t/react-app-how-to-import-sass-mixin/237459/9 "2021-01-16T17:54:04Z")

</div>

Closed on January 16, 2021, 5:54pm UTC


