简体   繁体   中英

Why create-react-app cant find my Sass variables

I create react app with create-react-app and setup the file structure like that:

src/
 -index.js
 -main.scss
 pages/
  -somepage.js
  -somepage.scss
 styles/
  -_variables.scss

index.js

import './main.scss';
...

main.scss

@import './styles/variables.scss';

_variables.scss

 $primary: #000;

somepage.js

import somepage.scss

somepage.scss

selector {
 property: $primary; <-- sass can't find that
}

Any ideas please? Thank you.

You need this...

npm install node-sass

https://www.npmjs.com/package/node-sass

Can you try this ?

@import './styles/variables';
@import './pages/somepage';

You could import all stylesheets in your main.scss and then all you need is import './main.scss'; in index.js . You also don't have to to specify the suffix.

Finding the File

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