Using Gulp how can I require jQuery in my script

I’m trying to do this

var $ = require('jquery');
$("document").ready(function() {
      console.log('hello world');
});

It’s not working. The console logs an error of

script.js:2 Uncaught TypeError: Cannot read property 'fn' of undefined

This is the gulp task responsible for the js file

gulp.task('js', function() {
   gulp.src( path.to.jsOriginalFiles ) //Get all these files
    .pipe(concat('script.js')) //and concat them into scrip.js
    .pipe(browserify())
    .pipe(gulpif(path.to.env !== 'development', uglify() )  )
    .pipe(gulp.dest(path.to.jsDistFiles))
    .pipe(browserSync.stream())
});

Thanks for your help

Did you run npm install --save jquery before this?

yes I did do that

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.