Saturday, 20 May 2017

Error: Cannot find module 'gulp-uglify/minifier'

Environment

Ubuntu 17.04

Steps

Installed Node via official instructions:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Installed gulp via official instructions:

npm install --global gulp-cli

Which caused permission errors, so followed official instructions:

# Make a directory for global installations:
mkdir ~/.npm-global

# Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'

# Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH

# Back on the command line, update your system variables:
source ~/.profile

Created a package.json file in my project folder with this content:

{
  "devDependencies": {
  },
  "dependencies": {}
}

Ran the following in my project folder:

npm install gulp --save-dev
npm install gulp-clean-css --save-dev
npm install gulp-concat --save-dev
npm install gulp-rename --save-dev
npm install gulp-sass --save-dev
npm install gulp-uglify --save-dev
npm install pump --save-dev
npm install uglify-js-harmony --save-dev

Which then populated the package.json file so it looked like:

{
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-clean-css": "^3.3.1",
    "gulp-concat": "^2.6.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-uglify": "^3.0.0",
    "pump": "^1.0.2",
    "uglify-js-harmony": "^2.7.7"
  },
  "dependencies": {}
}

The relevant task in gulpfile.js looks like this:

// BEGIN get gulp plugins
var gulp = require('gulp');
var pump = require('pump');
var rename = require('gulp-rename');
var uglifyjs = require('uglify-js-harmony'); 
var minifier = require('gulp-uglify/minifier');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
// END get gulp plugins

gulp.task('bundle_js', function () {
  // the same options as described above 
  var options = {
    preserveComments: 'license'
  };

  pump([
      gulp.src('scripts/*.js'),
      minifier(options, uglifyjs),
      concat('script_bundle.js'),
      gulp.dest('scripts_bundled')
    ]
  );
});

Running:

gulp bundle_js

Causes this error:

throw err;
    ^

Error: Cannot find module 'gulp-uglify/minifier'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/me/Desktop/myGulpProject/gulpfile.js:6:16)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)



via user1063287

No comments:

Post a Comment