I'm trying to get a basic build set up using Gulp and browserify, but keep seeing this error when trying to run the default task:
Error: Cannot find module 'src/js/main.js' from '/Users/ben/dev/git/myapp/'
var gulp = require('gulp');
var browserify = require('browserify');
var del = require('del');
var source = require('vinyl-source-stream');
var paths = {
main_js: ['src/js/main.js'],
js: ['src/js/*.js']
};
gulp.task('clean', function(done) {
del(['build'], done);
});
gulp.task('js', ['clean'], function() {
browserify(paths.main_js)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/'));
});
gulp.task('watch', function() {
gulp.watch(paths.js, ['js']);
});
gulp.task('default', ['watch', 'js']);
console.log("Hello!")
.
├── gulpfile.js
├── node_modules
│ ├── browserify
│ ├── del
│ ├── gulp
│ └── vinyl-source-stream
├── npm-debug.log
├── package.json
└── src
├── css
├── index.html
└── js
└── main.js
I can't understand why it's failing to find main.js. When I run this command from myapp/
, it works fine:
$ browserify src/js/main.js > build/bundle.js
Try using "./src/js/main.js" instead of "src/js/main.js" i.e:
var paths = {
main_js: ['./src/js/main.js'],
js: ['src/js/*.js']
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With