Reputation: 448
I'm trying to set up node-sass, following the instructions on CSS-Tricks. Node and npm are installed correctly, and the node-sass installation worked too. When I go to run node-sass --output-style compressed -o dist/css src/scss
, though, I get an error message stating
'node-sass' is not recognized as an internal or external command, operable program or batch file.
I've done a fair bit of Googling and searched Stack Overflow directly. My question isn't about "node" not being recognised as a command. I know node is working as I can run node -v
and npm -v
, and node-sass was successfully installed after running npm install --save-dev node-sass
(there's a folder in node_modules) and no errors appeared in the command line.
Other information: I am running Windows 10 and just did a clean install of node and npm before trying to use node-sass.
EDIT: I uninstalled and reinstalled with -g thanks to @Bhavik's suggestion, and it's now working
Upvotes: 21
Views: 86921
Reputation: 782
First, run npm install -g node-sass
as others have pointed out.
Now, the target of the command (sass.cmd
) is not located in the current working directory. For it to still be able to run, its location must be in your PATH (or Path) environment variable.
For me, the path is: C:\Users\Guy\AppData\Roaming\npm
Make sure to restart any terminal/IDE you were trying to run it in before trying again. Otherwise it won't recognize the new environment variable.
Upvotes: 0
Reputation: 474
This is a simple problem don't worry too much. Just go to package.json file and add this code
"devDependencies": {
"node-sass": "4.9.2"
},
"scripts" : {
"node-sass": "node-sass --output-style compressed -o dist/css/ scss --recursive"
}
and just save the file.
And run this command,
npm run node-sass
That's all
Upvotes: 0
Reputation: 71
You can simply run this code
Hopefully work
Upvotes: 6
Reputation: 1042
npm commands check "node_package" folder and try to run things there. You can try
npx run scss
to install scss and then run it, even if it is not installed before.
Upvotes: 1
Reputation: 4971
node-sass v4.13+
cd <root path of your project>
yarn add -D node-sass
// or
npm install -D node-sass
"scripts" : {
...
"compile:sass": "node-sass --recursive --watch <sass directory> --output <css directory>",
...
}
yarn compile:sass
// or
npm run compile:sass
Upvotes: 0
Reputation: 1
The below solves the problem
yarn global add node-sass-chokidar
Upvotes: 0
Reputation: 4904
You need to install it globally
npm install -g node-sass
Or add it in package.json
"devDependencies": {
"node-sass": "4.5.0"
},
"scripts" : {
"node-sass": "node-sass --output-style compressed -o dist/css src/scss"
}
And then do
1. npm i
, which in this case would be similar to npm install --save-dev node-sass
2. npm run node-sass
Reference: npm scripts, npm-run-scripts
Upvotes: 50