Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use globally installed gulp modules?

I tried this tutorial to basically setup my gulp project and activate less processing and watching. It works. Now I'd like to install the modules globally, in order to acces them from everywhery on the machine and not to installa them for every project:

npm install --global gulp-less
npm install --global gulp-watch
npm install --global gulp-autoprefixer
npm install --global gulp-plumber

Now I want to run gulp in my project folder, but gulp cannot find the globally installed modules:

$ cd /my/project
$ gulp
module.js:327
    throw err;
    ^

Error: Cannot find module 'gulp-less'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/root/temp/gulptest/gulpfile.js:9:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

How to get it working and use global gulp modules?

like image 907
automatix Avatar asked Dec 24 '22 09:12

automatix


2 Answers

The solution was npm-link. I had to link all my local packages to global counterparts:

npm link gulp
npm link gulp-less
npm link gulp-watch
npm link gulp-autoprefixer
npm link gulp-plumber
npm link path

Now it works.

Some StackOverflow posts to this subject:

  • "Skip local installation of Gulp"
    • Aperçu's answer
  • "Why do we need to install gulp globally and locally?"
    • Derek Greer's answer
like image 107
automatix Avatar answered Dec 27 '22 21:12

automatix


1. Install gulp globally:

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.

$ npm install --global gulp-cli

2. Install gulp in your project devDependencies:

$ npm install --save-dev gulp

Read more... https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md

like image 33
Love Bdsobuj Avatar answered Dec 27 '22 22:12

Love Bdsobuj