node-sass: command not found after installing globally - sass

I had node sass installed globally on my machine previously then after a reset I had to reinstall.
I have tried installing it globally as I use it to compile .scss files in specific directories. After trying to install it globally and reinstall it globally it does not work. I did this on a separate machine and it works without issues.
Tried the following:
npm i node-sass -g
npm install node-sass
npm install -g node-sass
$ node-sass -v
bash: node-sass: command not found

You can use npx to run node-sass. npx will check if you have a global path to the npm package, and if not, it will temporaily download and execute it.
For instance, to run node-sass and check version.
npx node-sass -v

I tried installing node-sass globally on my linux PC, then running node-sass -v and it worked.
Assuming that you are running your commands on Linux, you might not have your npm home in your $PATH, so your OS doesn't know where to look for when you write node-sass.
To solve this look for your npm home folder (where you have installed node-sass), then add that path to the $PATH environment variable.
You can run npm list -g, and the first output line is the path of your global npm sources (the directory you need is bin, not lib).
You might also want to follow this guide to be able to run npm packages commands as root: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally.
If you do this you should re-install all your global packages in order to have them all in the same directory.
If you are using Windows, is basically the same, only the method of setting the env var changes.

Related

Where does "npm install -g <package>" install the package? [duplicate]

This question already has answers here:
Where does npm install packages?
(23 answers)
Closed 3 years ago.
I have installed some packages using npm install -g and was wondering were they were actually installed?
If I use npm install they are installed in the current directory under node_modules it appears.
I understand how to use the -g flag from (when to use) and (how to use).
When you do npm install -g <package>” then it means you want to install that particular npm module system wide (globally). And when you do without the g option, then module would be installed locally inside the current directory called node_modules.
The -g(global) directive tells npm to install the package in the global shared node_modules folder and usually you get that where nodejs resides(Path: C:\Program Files\nodejs).This will also allow you to access the module from the command-line at global level.
You can also check where global packages/libraries are installed:
Run below command
npm list -g or npm root -g
In windows:
C:\Users\admin>npm list -g
C:\Users\admin\AppData\Roaming\npm\node_modules
In mac: you find node_modules here
/usr/local/lib/node_modules
Whenever you put -g then it installed that file globally and that can accessed in any folder you wants then you don't need to install again again same package.
For more details.
You can also check where local packages/libraries are installed:
run npm list or npm root
And, when you simply install then that particular package restricted to that folder.
So, whenever you package dependencies at global level then you need to put -g while installing folder.So,
If you’re installing something that you want to use in your program,
using require('whatever'), then install it locally, at the root of
your project.
If you’re installing something that you want to use in your shell, on
the command line or something, install it globally, so that its
binaries end up in your PATH environment variable.
check this.
Hope it helps.Thanks

"exp: command not found" How do I add expo cli to path?

I installed the expo cli with
npm i -g exp
then I run
exp
and I get
-bash: exp: command not found
I'm guessing I didn't add exp to path. So how do I do this properly? Nothing I've tried so far works.
This suggested 3 steps solution worked for me:
First check if ~/.npm-global/bin is in your path: echo $PATH. If it isn’t there, you will need to add it to the path.
Open up ~/.bash_profile then add the following line to the bottom: export PATH=$PATH:~/.npm-global/bin
Finally, back in the shell, type: source ~/.bash_profile
Hopefully that will have fixed your problem.
1. Find the path where expo is globally installed by npm:
npm bin -g
2. Add path from Step 1 to paths file:
sudo vi /etc/paths
3. Restart the Terminal
You should try npx expo init <your_app_name> to test.
It worked for me.
I also had a hard time getting expo command to work on Mac. Here are the steps I took to get it working.
npm root -g shows the directory the global modules are installed in:
/usr/local/Cellar/node/11.7.0/lib/node_modules
That directory might be different for you. After confirming expo is in there, edit ~/.bash_profile and add the line:
export PATH=$PATH:/usr/local/Cellar/node/11.7.0/bin
Save & exit, then run source ~/.bash_profile
Now the expo command should function as intended.
try sudo npm install --global expo-cli
this worked for me.
➜ MobileDev git:(campaigns-responsive) ✗ expo whoami
› Not logged in, run expo login to authenticate
➜ MobileDev git:(campaigns-responsive) ✗ expo init App
✔ Choose a template: › blank a minimal app as clean as an empty canvas
✔ Downloaded and extracted project files.
📦 Using npm to install packages.
✔ Installed JavaScript dependencies.
✅ Your project is ready!
To run your project, navigate to the directory and run one of the following npm commands.
- cd App
- npm start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- npm run android
- npm run ios
- npm run web
exp was replaced with expo
To install Expo CLI, just run npm install -g expo-cli (or yarn global add expo-cli, whichever you prefer).
Following on this issue, I found I had multiple global folders so I started using a .npm-global folder as shown here: https://docs.npmjs.com/getting-started/fixing-npm-permissions
And now it's all clean and in control.
I had a similar issue.
-bash: expo: command not found
It turns out the command to install expo
npm install -g expo-cli was referencing an older version of node on my machine; when checked using npm root -g.
So I had to uninstall nvm/node, deleted any remnant folders & files of .nvm and shortcuts for nvm in /usr/local. Then reinstalled node and ran npm install -g expo-cli again.
That fixed my issue.
sudo npm install --unsafe-perm -g expo-cli
If you're using git bash on windows, add npm path to your system path variables. Generally located on this location:
C:\Users\<Username>\AppData\Roaming\npm
Then open the bash and command npm start. Hope this will help.
I solved it by putting this in my PATH environment variable / user variable:
C:\Users\{userName}\node_modules\.bin
yarn expo start
Worked for me.
npx create-expo-app project-name

NPM Packages (with CLI) installed globally return command not found

I've had this happen twice to me before. The first time I assumed it was an error with NPM, so I uninstalled Node & NPM and didn't use the package that was giving me an error.
I did a fresh install & began working on another project. I'd installed the package (and the version of it with cli). The command line command worked during the terminal session during which i'd installed it both globally and in my project. However in other terminal tabs and in new terminal sessions the command returns command not found.
when I run npm root i receive:
/Users/MYUSERNAME/node_modules
and when I run npm root -g, i receive:
/Users/MYUSERNAME/.npm-global/lib/node_modules
For what it's worth the two packages I've tried this with are mjml (and mjml-cli) and gulp (and gulp-cli). I've uninstalled both and reinstalled again from my root directory using the -g flag and that doesn't seem to have changed anything.
I appear to have missed this somewhere in the googling I did before asking this question.
Apparently I had been accidentally installing global packages in my local folder (/Users/YOURUSERNAME/node_modules).
Running npm config set prefix /usr/local fixed the issue.

Do I have to install grunt locally or is it just best practice ...?

or neither.
I installed both grunt-cli and grunt globally as such
inst_grunt(){
# installs the grung-cli to
# /usr/local/lib/node_modules/grunt-cli
sudo npm install -g grunt-cli
# installs grunt based upon the package.json file to
# /usr/local/lib/node_modules/Grunt
sudo npm install -g
}
I thought I could simply run
grunt --gruntfile /Users/a/root/config/Gruntfile.js watch
as stated here:
How do I run grunt from a different folder than my root project
but alas I get this error:
as-MacBook-Air:config a$ grunt --gruntfile
/Users/a/root/config/Gruntfile.js grunt-cli: The grunt command line
interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or
grunt hasn't been installed locally to your project. For more
information about installing and configuring grunt, please see the
Getting Started guide:
http://gruntjs.com/getting-started
The grunt file is there so I'm assuming it is looking for a local grunt installation.
You do have to install it locally in order to call functions on it within the gruntfile.
This way your project can specify what version of Grunt should be used (edit) in your package.json file.

Grunt installed but not working - "Command not found" on Mavericks

I'm trying to use grunt with sass and have been following these guides:
http://gruntjs.com/getting-started
http://benfrain.com/lightning-fast-sass-compiling-with-libsass-node-sass-and-grunt-sass/
http://www.hongkiat.com/blog/grunt-command-not-found/
I've:
Intsalled node.js
Installed the command-line version of grunt: sudo npm install -g grunt -cli
Added the path from the grunt installer to my bash profile: export PATH=/usr/local/lib/node_modules/grunt/bin:$PATH
Made the profile an executable: source ~/.bash_profile
Setup package.json and Gruntfile.js files in my project root
Installed grunt into the project: cd /path/to/project/root/ and sudo npm install
But when I try to run grunt I see: command not found
It's the same if I run: grunt --version
I wasn't sure if the bash path needs /bin on the end as per the blog posted above but have tried it both ways:
/usr/local/lib/node_modules/grunt/ and /usr/local/lib/node_modules/grunt/bin/
I've also run the grunt installer several times but didn't see any errors so am positive it's installed - can anyone see what I'm doing wrong? I'm running OSX mavericks incase this is the issue.
Any pointers in the right direction would be much appreciated.
Cheers
You have a typo in your command. The package is named grunt-cli without the space.
Update the command to:
sudo npm install -g grunt-cli
And all should work as expected.
Hope this solution also might be helpful to someone. In my case it was a bit trickier.
In command line type the following command
npm install grunt-cli -g
This will show you the location where the grun client is installed:
Copy this location and paste it into a file browser. Was this in my case.
C:\Users\zkhaymed\AppData\Roaming\npm\node_modules\grunt-cli\bin
This will open you the location of a grunt file.
Click on the address line of the location and copy it as a text clicking on the right mouse button.
Now go to the Advanced properties of the system at control panel, and paste this address into a System variables and user variables without deleting the other variables.
I was having a very similar issue, hopefully this helps.
1) You want to check where node and npm are actually installed. If you used a package manager, such as Homebrew or MacPorts, there may be an issue with the location. Just use the downloadable installer from node.js website. Make sure to use the current version, not the long term support (LTS). The installer will install node and npm in /usr/local/bin, which should already be in your PATH. If you already have node/npm installed you can use which node and which npm to see where they are currently located. You should see /usr/local/bin/node and /usr/local/bin/npm, respectively. You will need to update npm after installing with npm update -g npm. This may require sudo.
2) Once node and npm are correctly installed/updated go to the project's root directory (where you have the Gruntfile.js and package.json) and install Grunt using npm install grunt --save-dev. Remember that Grunt After doing so you should see a new folder called node_modules.
3) Make sure to do the previous step before installing the CLI. You can use Grunt's getting started documentation to help guide you the rest of the way. Just be aware that the instructions for installing Grunt are further down the page than installing the CLI, which makes it somewhat confusing. When Grunt and Grunt-CLI are installed run npm install and run grunt in the command line to execute your Gruntfile.js.
You should now be able to see the versions installed. Note that if you are outside of a project's root directory you will not see a version of Grunt but you will see the Grunt-CLI version. This is because the CLI was installed globally (used from any directory/subdirectory) but Grunt is installed on a per-project basis.
Hopefully this helps!
I just ran into this scenario as well. The following worked for me:
Try deleting C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache (if it exists) and reinstalling global npm modules.
Source: https://github.com/nodejs/node/issues/29287
I had to add this to the PATH (on a Mac after brew install node ):
export NPM_HOME=/usr/local/Cellar/node/6.3.1/libexec/npm
The npm install was not effective, no matter what args I passed to it.

Resources