Cannot find module '~/testproj/src/app.js 'from'~/testproj' error when auto-transpiling browserify on gulp watch

Asked 1 years ago, Updated 1 years ago, 109 views

As per the title, I am trying to use gulp to automatically execute the file monitoring transpile of browserify.

I configured gulpfile.js as follows:

var gulp=require('gulp');
varbrowserify=require('browserify'
var source=require('vinyl-source-stream');

gulp.task('browserify', function(){
  browserify({ entries: ['src/app.js']})
  .bundle()
  .pipe(source('bundle.js'))
  .pipe(gulp.dest('./js'))
});

gulp.task('default', function(){
  gulp.watch('src/app.js', ['browserify']);
});

When I ran gulp browserify on the command line, the code was successfully transferred, but when I automatically run it with file monitoring using the watch, the following error occurs the moment I update the target file:

Cannot find module'~/testproj/src/app.js 'from'~/testproj'

I can't find the app.js because of the Cannot find module, but I don't know what's wrong with the app.js because it actually exists in the ~/testproj/src directory.

Please let me know if you notice anything.

node.js gulp browserify

2022-09-30 19:21

1 Answers

I don't know the direct cause, but it's common to use watchify for browserify.

https://github.com/substack/watchify


2022-09-30 19:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.