Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To import Sass files, you first need to install node-sass

Running create-react-app, I get the error in my create-react-app application:

To import Sass files, you first need to install node-sass. Run npm install node-sass or yarn add node-sass inside your workspace.

I do have node-sass installed.

package.json:

  "devDependencies": {
    "node-sass": "^4.13.0"
  }

project node_modules folder:

enter image description here

I've uninstalled, reinstalled, updated, cleaned cache, etc. How do I fix?

like image 445
user210757 Avatar asked Nov 08 '19 15:11

user210757


People also ask

Does Sass loader require node sass?

node. js - Sass-loader requires node-sass >=4 even if that exist - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

Is node sass the same as Sass?

Node sass is a library that allows binding for Node. js to LibSass, the C version of Sass's stylesheet preprocessor. It compiles . scss files to CSS with speed and automatically through connected middleware.

Why node Sass is required?

It enables a developer to create code in another language and translate it into CSS , and it compiles SASS to CSS at an incredible speed. It has introduced various new features like: nesting. data variables.


Video Answer


4 Answers

In my case I had the same problem even though node-sass was already installed in my project directory.

To import Sass files, you first need to install node-sass. Run npm
install node-sass or yarn add node-sass inside your workspace.

What I figured out is, my project was running on the react scripts installed globally, and there was an another version inside my local project directory. There was a conflict in getting the base path of 'node-sass'.

I uninstalled the local react-scripts and installed it again in the local project directory. Run,

npm uninstall react-scripts then
npm install react-scripts

That fixed my problem!

like image 198
Babitha Avatar answered Oct 08 '22 17:10

Babitha


what worked for me was that I uninstalled global node-sass and installed it in my current project directory

npm uninstall -g node-sass

npm install node-sass

make sure to stop npm start until after installation, if possible restart your system when installation is done

like image 38
Chukwuemeka Maduekwe Avatar answered Oct 08 '22 19:10

Chukwuemeka Maduekwe


I had the same issue and setting the SASS_PATH environment variable fixed it for me.

For example if you use docker-compose.yml then add:

environment:
  - SASS_PATH=node_modules:src

Maybe someone else can explain why this was needed.

like image 1
Philippe Gerber Avatar answered Oct 08 '22 19:10

Philippe Gerber


In my case below was my error,

./src/modules/TestListing/components/SurveyCard/index.scss 

/usr/local/lib/node_modules/react-scripts/node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!

/usr/local/lib/node_modules/react-scripts/node_modules/postcss-loader/src??postcss!

/usr/local/lib/node_modules/react-scripts/node_modules/resolve-url-loader??ref--6-oneOf-5-3!

/usr/local/lib/node_modules/react-scripts/node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!

./src/modules/TestListing/components/SurveyCard/index.scss)


To import Sass files, you first need to install node-sass.
Run `npm install node-sass` or `yarn add node-sass` inside your workspace.

The error was happening even though I had installed node-sass globally which was weird.

I figured react-scripts could not able to recognize node-sass in it's environment , Hence I have added node-sass dependency in globally installed react-scripts package

cd /usr/local/bin/node_modules/react-scripts
sudo npm install --unsafe-perm node-sass

In the above command I am actually installing node-sass to a react-script package which is a library, It could fix the issue in my case,

Becareful on the commands, Because I am dong --unsafe-perm, Read it before you do


like image 1
Siva Kannan Avatar answered Oct 08 '22 19:10

Siva Kannan