37

I had previously installed gulp globally using npm install gulp -g. Then I cloned an existing project, and that required me to use its own gulp. Now when I do a gulp -v from outside my project folder, I get a mismatch like this.

C:\Users\userme>    
[11:14:05] CLI version 3.8.11
[11:14:05] Local version 1.0.0

And when I do a gulp from my project folder, I get this.

C:\project\new\tools>
[11:14:26] CLI version 3.8.11
[11:14:26] Local version 3.8.11

Now I have not been able to merge my JS files properly using gulp (I'm getting some weird formatting errors in the min file) and I suspect it has something to do with this mismatch.

  1. Is there a way to remove the global gulp version, but keep the project specific gulp?
  2. Or can I update my global version gulp to @3.8.11?

Note - I did try updating the global gulp by using npm update gulp@3.8.11 -g but nothing happened. i still get the mismatch.

Update to describe the issue: I am using gulp to merge multiple JS files into 1 single main.js file. The formatting that I get in the merged file has a syntactical error in it.

Expected output in merged file -

...
define('utils/knockoutBindings/slider',['require','ko','jquery'],function(require) {
    'use strict';
    var ko = require('ko');
    var $ = require('jquery');
...

Actual output in merged file (this 1 line of code below is wrongly replacing the entire 4 lines above) -

...
var'utils/knockoutBindings/slider',['require','ko','jquery'],function(require) {
...

It might seem that there is an issue in the gulp code, but the same code is used by other users and it works well on their end. The only difference we have found is in the mismatch in my gulp versions.

rodiwa
  • 1,690
  • 2
  • 17
  • 35

6 Answers6

32

I am answering my own question, just so it is useful for others.

  1. Is there a way to remove the global gulp version, but keep the project specific gulp?

No. AFAIK, you are required to install gulp globally as well as one specific to your project.

More info on gulp versions here.

  1. Or can I update my global version gulp to @3.8.11?

Since I was facing a mismatch in my local version, I had to update it from the project folder itself.

npm install gulp@3.8.11 --save

More info on this here.

Community
  • 1
  • 1
rodiwa
  • 1,690
  • 2
  • 17
  • 35
  • 2
    You don't actually need the global `gulp`. Just install `gulp-cli` globally. – Franklin Yu Sep 05 '16 at 04:57
  • 1
    As per the gulp documentation: If you have previously installed a version of gulp globally, please run npm rm --global gulp to make sure your old version doesn't collide with gulp-cli. – Sourabh Sep 15 '16 at 12:24
  • 10
    can someone explain to me why before upgrading my gulp-cli it was at version 3.9.1, and then after upgrading to the latest its now at 2.2.0? `[18:55:40] CLI version 3.9.1 [18:55:40] Local version 4.0.2` Was driving me nuts, until I saw on npm gulp-cli page that the current version is 2.2.0? – rolinger Aug 28 '19 at 23:47
18

To update your Local version npm install gulp@version_you_need

To update CLI version npm install -g gulp@version_you_need

Meir Snyder
  • 789
  • 1
  • 6
  • 16
3

Removing node_modules folder and running npm install gulp within that dir sorted my issue out.

Basavaraj Hadimani
  • 1,094
  • 12
  • 21
decoder88
  • 480
  • 4
  • 6
2

npm install -g gulp wasn't fixing it for me, from either in or out of the project folder. My gulp version was already correct in my package.json file. All I had to do was run npm install from within the project folder, and the gulp version from in the project folder was corrected.

Andrew
  • 5,839
  • 1
  • 51
  • 72
1

Updating both the local version same as that of the global version fixed the issue. My initial gulp -v yielded CLI version 3.9.1 and Local version 4.0.0. I updated the local version from within the project folder npm install gulp@3.9.1 --save. This resolved my issue .

Masoud Keshavarz
  • 2,166
  • 9
  • 36
  • 48
1

Gulp 4 uses an updated CLI which needs to be updated globally. This CLI is backwards compatible with any Gulp 3.X projects you may have locally - Read more.

It seems that the latest version (at the time of this post) of gulp-cli is 2.3.0 which means there will always be a mismatch.

If you run npm install -g gulp, then the latest version of the CLI will be installed. If you have any other version installed then it will update to the latest version.

The local version's latest release (at the time of this post) is 4.0.2.
Run npm install --save-dev gulp to install the latest version of Gulp in your project folder as a dev-dependency. Like with the CLI version it will update if you have an older version.

Mismatched versions work like normal.

SIDE NOTE: Remember to prefix global installs with sudo if you're working on a Mac and you have admin rights e.g. sudo npm install -g gulp.

BUT if you don't have admin rights and you can update the local version, but not the global version, then you can run node ./node_modules/gulp/bin/gulp.js from your project folder and it will execute the gulp file, even if you have the wrong CLI version, but you need to have the default task set up.

Ludolfyn
  • 1,806
  • 14
  • 20