I have a project that is using node npm and gulp. When we build the project node 5 is installed in the local directory and runs npm install (compiling all node modules agains node v5) I globally have node version 7 installed.
We have a gulp task that uses node-sass which is compiled against v5 but when I try to run the task it uses the global version and node-sass errors out out "Missing binding"
How can I run it using the local version of node?
nvm is very helpful for managing and switching between multiple versions of node, including your globally installed packages.
If you are looking to automate it, you could just add the console command to use the needed version via nvm within your gulp task.
e.g. "nvm install v5.0.0"
To expand upon #dmfay's answer, you should have node 5 installed (via nvm or tj's n).
However you can include in your package.json for the project such that it relies on node 5. (Under the "engine" property)
None of the install/rebuild solutions resolved the issue for me (using gulp).
Here is how I resolved it:
1) Download the missing binding file from the repository.
2) Rename the file binding.node.
3) Create /node-modules/vendor/<operating system>/ (for my version of node/node-sass the <operating system> directory for linux is linux-x64-64, use folder name from missing binding error message)
4) Add binding.node file to /node-modules/vendor/<operating system>/.
5) run gulp
Related
I have Node version 16.13.1 installed globally in my machine. I have a project where I want to downgrade the version to 14.19.1. I used the command npm install node#14.19.1 --save-exact to downgrade, and this version is reflecting in my package.json file.
The problem is, when I run node -v at my project's root folder, the version is returned as 16.13.1. To check this, I made an entry in scripts in package.json - "v": "node -v". When I run npm run v, the output is 14.19.1.
It's clear that my project's Node version was downgraded successfully. So, why does Node show me the global version when I check it from my project's folder? Is there flag to use with node -v to check the local version?
To use multiple node versions in your system you have to use nvm. Which is useful to install multiple node versions and easy to switch node versions as per project requirements. NVM Installation Guid
Because of our company policies I cannot install nvm on my machine to have multiple node versions. Is there any npm package using which I can install and switch to different versions of node ?
I have a build tool for a proprietary system that needs an old node version.
I just downloaded and unzipped that version into a folder and run a batch script on the console to put the old node as the first %PATH% entry. After running the batch script all node calls use the old version
MY SITUATION
I have installed version Node v6.2.0 using n on Ubuntu 14.04. It's located under path /usr/local/n/versions/node/6.2.0 (by using npm prefix -g).
My global packages installs in that directory under lib/node_modules but I can't use that packages from command line globally.
NOTE
Earlier I was using older version Nodejs 5 installed different way. And packages installed globally with that version of Node are available now, but not new ones which I installing now.
MY QUESTION
Is there a trick or something to point node_modules directory from which its packages could be used globally?
Your global package binaries should be available here:
/usr/local/n/versions/node/{NODE VERSION}/bin
Add it to your path (in .bashrc or .bashprofile or .zshrc):
NPM_GLOBALS=/usr/local/n/versions/node/{NODE VERSION}/bin
PATH=$NPM_GLOBALS:$PATH
Then restart your console or just run source ~/.bashrc
Also, if you're working with multiple versions of node, I highly recommend nvm for installing and managing them.
I simply added export PATH=~/.npm-global/bin:$PATH to my .zshrc file.
I have several unrelated projects that use bower.
I'm wondering if it is better to install bower globally or locally.
In the ‘global’ case, if a project upgrades bower to a newer version that has breaking changes (e.g. no longer supported flags), all other projects may be impacted.
In the local-only case, you get project isolation, but in the CLI, instead of just
> bower install
you have to run
> node ./node_modules/bower/bin/bower install
which is a keyboard-full.
For other node tools (e.g. grunt, karma) there exist separate globally-installable packages (grunt-cli, karma-cli) that:
are runnable from anywhere
are just simple .cmd files
look at the CWD and pick the local version of grunt/karma, and run that with the original parameters
...so you get the best of both worlds.
For bower, strangely, there is no bower-cli package.
Any idea why?
And, more to the point, is there a (simple) way to have the bower command runnable from anywhere, but targeting the bower version installed at the current working directory?
BTW, I'm on Windows.
In my package.json file, I have bower listed as a dependency. After I run npm install, bower gets installed locally. When I try to run bower after installing it locally I get an error
"bower" is not recognized as an internal or external command
It seems the only way to resolve this is to install bower globally. Why should I have to do this? If my project contains a local copy of bower, why won't node use it?
Installing locally makes bower available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.
Edit: This documentation explains it pretty thorougly.
You can execute your local instance by typing the line below in cmd:
node_modules/bower/bin/bower <bower args>
We use both PHP and JavaScript, so we have composer and npm.
Each of the projects we work on have different packages both for runtime of the package as well as build/dev tools.
As there are version constraints in each project, installing version x of a package globally (that would be run from the command line), would cause us issues, we install all the tooling in each package. Much easier to define in the appropriate composer.json / package.json files.
But running the CLI tools is a pain if you have to constantly add an additional path to the command.
To that end, we have recommend to the team that the following paths are added to your $PATH in the appropriate .bashrc (or equivalent):
./vendor/bin:./node_modules/.bin
(EDIT: For Windows, the paths would be .\vendor\bin;.\node_modules\.bin;)
So, whilst in project X, we have access to the CLI tools for that project. Switch to project Y, and we get that projects tools.
Sure, you are going to get duplications, but each project is maintained by different teams (and some people are in multiple teams), so again, having 1 version in the global setup is an issue there.
Usually you install NPM modules globally if you want them included in your path to be ran from the command line. Since it is installed locally you will have to run it from the node_modules folder.