M
M
Mary Solar2017-04-06 13:28:32
JavaScript
Mary Solar, 2017-04-06 13:28:32

Why does an error appear when loading a task?

Hello!
I finally got to gulp. I'll start over:
1) I installed all sorts of things like compiling sass, browsersync and all that
2) It came to connecting concat and uglifyjs: I
installed everything as it should be through the console. Installed:
5c13d87742ca46968f591dd39b184430.png
3) I connect:

var gulp         =  require('gulp'), //  Gulp
    sass         =  require('gulp-sass'), // Sass пакет,
    browserSync  =  require('browser-sync'), // Browser Sync
    autoprefixer =  require('gulp-autoprefixer'),// автопрефиксер
    concat      = require('gulp-concat'),//  gulp-concat (для конкатенации файлов)
    uglify      = require('gulp-uglifyjs'); //  gulp-uglifyjs (для сжатия JS)

4) I create a task:
gulp.task('scripts', function() {
    return gulp.src([ // Беру все необходимые библиотеки
        'app/libs/jquery/dist/jquery.min.js' // Беру jQuery
    ])
        .pipe(concat('libs.min.js')) // Собираю их в кучу в новом файле libs.min.js
        .pipe(uglify()) // Сжимаю JS файл
        .pipe(gulp.dest('app/js')); // Выгружаею в папку app/js
});

5) I enter into the console gulp scripts
And there is such a problem:
W:\!Mary\myproject>gulp scripts
module.js:471
    throw err;
    ^

Error: Cannot find module 'gulp-concat'
    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> (W:\!Mary\myproject\gulpfile.js:9:19)
    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)

W:\!Mary\myproject>

And there is another garbage: if I swap concat and uglify when connecting
uglify    = require('gulp-uglifyjs'), //  gulp-uglifyjs (для сжатия JS)
    concat   = require('gulp-concat');//  gulp-concat (для конкатенации файлов)

then the error is like this:
W:\!Mary\myproject>gulp scripts
module.js:471
    throw err;
    ^

Error: Cannot find module 'gulp-uglifyjs'
    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> (W:\!Mary\myproject\gulpfile.js:9:19)
    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)

W:\!Mary\myproject>

Tell me, please, what is the error? Already exhausted all, although it seems that everything should work. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex, 2017-04-06
@MaryT

var concat = require(' concat '); // not gulp-concat
var uglify = require(' uglifyjs '); // not gulp-uglifyjs
Look again closely at devDependencies

K
Konstantin Kitmanov, 2017-04-06
@k12th

uglify-js is worth it, gulp-uglifyjs is not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question