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
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
You can simply run this code
npm install -g sass
sass --watch sass:css
Hopefully work
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.
The below solves the problem
yarn global add node-sass-chokidar
node-sass v4.13+
Install node-sass in your project locally
cd <root path of your project>
yarn add -D node-sass
// or
npm install -D node-sass
Add a script to your package.json
"scripts" : {
...
"compile:sass": "node-sass --recursive --watch <sass directory> --output <css directory>",
...
}
Run the script from the command line
yarn compile:sass
// or
npm run compile:sass
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
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.
Related
I'm trying to use gulp for the first time.
Following instructions online, I installed it globally as well as locally, but I still get the
'gulp' is not recognized as an internal or external command[...] error. When using PowerShell instead of cmd the error is the term 'gulp' is not recognized as the name of a cmdlet, function, script file[...]
I've tried:
installing gulp-cli in addition to gulp
adding / changing PATH variables
restarting my PC
running npm install -g npm#latest to make sure npm is up-to-date
I'm stumped. On top of all that, I have other npm packages installed globally that work fine.
Edit: I fixed this by adding npm to my PATH environment variable. I had been adding it to NODE_PATH, which doesn't work for CLI use.
"Global install" with the -g flag basically means you install the command provided with the package.
To globally install gulp:
npm install gulp -g
You can add the gulp script in the package.json file and run the gulp command using npm.
Ex:
gulp task name : helloTest
Add below code in package.json:
"scripts": {
"helloTest": "gulp helloTest",
}
And now type below command in terminal:
npm run helloTest
I have installed serve with npm as "npm install serve -g" and also with yarn "yarn global add serve", but when I try to run "serve -s build" it says that "Command 'serve' not found.
You should not install the packages globally.Try to do the following-
npm uninstall -g serve
npm i -S serve
Let me know if this works.
I had same problem too and this helped me to fix it so try this after installing serve;
npx serve -s build
or
npx serve -s build -p 8000
(8000 = it depends by your choice)
I don't know why but this worked for me
None of these above answers worked for me, so this is what works for me :
sudo su
npm install -g serve
Installing as root helps globally installing serve
Make sure to have this in your .bashrc or .zshrc
if you're using Yarn:
export PATH="$PATH:$(yarn global bin)"
if you're using NPM:
export PATH="$(npm bin -g):$PATH"
So that the shell would know where to look for executables such as serve, npx, live-server etc that are installed globally.
Make sure to reload your shell config:
source ~/.bashrc // or ~/.zshrc
If anyone still gets the problem, try this:
npm uninstall -g serve
npm i -S serve
yarn global add serve
I faced the same problem, what I did was run the command yarn serve -s build
If you got it installed with npm then you can just add npm before the suggested command
I wanted to know how to use nodemon, and push it to a git repo, and have other developers on the project be able to use nodemon without having to run the command npm install -g nodemon. Ideally, I would like all developers on the project to be able to just run npm start and nodemon is called whether or not it's installed globally. I've already run npm install --save-dev nodemon, and I'm mostly curious if there is a way to get nodemon to be run from within node_modules, in my start command in the scripts section of the package.json file.
If you install it locally, i.e. without the -g flag, it's available in ./node_modules/.bin/nodemon. So just configure that path in your npm start script.
For example:
"start" : "./node_modules/.bin/nodemon app.js"
I am working with npm on a web app and I found an issue when using some packages that requires terminal commands to run such like nodemon and concurrently
I installed it via
sudo npm install --save-dev nodemon
and when I try to use it via:
nodemon ./server.js
I get an error
nodemon command not found
and the same when I used concurrently
I tried also with
sudo npm install --save nodemon
and it doesn't work.
it only work if I installed it globally
sudo npm install -g nodemon
Why I can't use it when install locally?
Note: I can found the executable file at node_modules/.bin
but this following not working as well
node_modules/.bin/nodemon ./server.js
Global packages can be launched directly because they are saved in your PATH directory by default. If you saved a package locally you can see it on node_modules/.bin/ as you mentioned. So there are 2 ways to achieve what you want if you want to run an executable package if installed locally:
You can run it via terminal as ./node_modules/.bin/nodemon yourscript.js
Or via npm scripts in your package.json file, you do this:
{
"scripts": {
"nodemon": "nodemon yourscript.js"
}
}
and execute npm run nodemon.
The 2nd approach works for both packages installed globally or locally.
I prefer installing packages locally, so my other apps won't get affected especially if I'm using different package versions per project.
UPDATE
On npm#5.2.0 onwards, it comes with a binary called npx. So you can run specific packages on the terminal just by npx [package] and it executes either your local or global npm package. In your case it should be something like npx nodemon server.js.
Because it's in your node_modules/.bin folder, not your PATH.
You can either use ./node_modules/.bin/nodemon or $(npm bin)/nodemon to call nodemon.
To run any locally installed npm module (Mocha, Eslint, Nodemon, etc.), you can now use npx. Try npx nodemon server.js.
I also recommend setting main within your package.json to point to the script you want to run (index.js by default), so you could just run npx nodemon or nodemon (if globally installed) and it will know which script to run.
This is because the local node_modules folder is not in your PATH. See the link to the duplicate question for more details.
I have a package.json in which some modules have to be installed globally,below is the part that i added below dependencies
"scripts": {
"preinstall": "npm i -g supervisor",
"preinstall": "npm i -g forever"
}
But when i ran npm install i got the error as below
npm WARN package.json aaa#0.0.0 No README.md file found!
npm WARN cannot run in wd aaa#0.0.0 npm i -g forever (wd=/home/administrator/AAA)
All the modules to be installed locally are getting installed,but only gloal installation is throwing an error.I am stuck here any help will be much appreciated.
Put this in your package.json :
"config":{
"unsafe-perm":true
}
And install your module as root.
Also I think that the switch preferGlobal : Documentation, is created for modules that prefer to be installed globally. You might want to change your program logic to use programatically forever module.
Install your modules locally and then execute them via the bin folder in the local node_modules directory
npm install -S forever
ls node_modules/.bin/
To start your app execute
node_modules/.bin/forever start app.js