【问题标题】:Gulp/Browserify ErrorGulp/Browserify 错误
【发布时间】:2016-08-03 18:53:24
【问题描述】:

我是 node 新手,并尝试按照本教程使用 gulp 设置 browserify:https://www.learnhowtoprogram.com/javascript/introduction-to-javascript/using-browserify-with-gulp。请帮忙,我试过谷歌搜索,没有解决方案。

我的 gulp 文件显示:

var gulp  = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
gulp.task('jsBrowserify', function() {
  return browserify({ entries: ['./js/pingpong-interface.js'] })
    .bundle()
    .pipe(source('app.js'))
    .pipe(gulp.dest('./build/js'));
});

我在终端跑了:

gulp jsBrowserify

这应该会创建“构建”文件夹。

相反,我得到了错误:

C:\Users\danrusu\Documents\Coding Docs\projects\pingpong>gulp jsBrowserify
(node:7728) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[11:04:15] Using gulpfile ~\Documents\Coding Docs\projects\pingpong\gulpfile.js
[11:04:15] Starting 'jsBrowserify'...

events.js:160
      throw er; // Unhandled 'error' event
      ^
 SyntaxError: Unexpected token

【问题讨论】:

    标签: gulp browserify


    【解决方案1】:

    browserify 调用需要.on('error', callback) 管道来捕获错误,即使没有错误。通常,我定义如下:

    function handleError(message){
      // print the message to console
    }
    

    然后可以做:

    return browserify({...})
      .on('error', handleError)
      .pipe(...)
      ...
    

    我可能有确切的语法错误,但您可以轻松地通过 browserify 的文档找到确切的语法并调用它需要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多