使用gulp with babelify + browserify无法找到模块

时间:2016-06-24 10:29:21

标签: javascript gulp browserify gulp-babel

我尝试使用gulpecm6中的javascript代码转换为ecm5,这没关系。 gulp-babel在已转换的代码中添加了require,现在我需要在浏览器中使用此代码,并且必须browserify代码。

当我在终端中运行此命令时,它会显示以下错误:

我该怎么做才能解决这个问题?我做错了什么?

PD:感谢您的帮助。

雅斯特尔

命令

gulp build

输出

Error: Cannot find module 'log' from '/home/ismael/projects/js-evolve/gulp-babel/dist'
    at /home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:46:17
    at process (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:173:43)
    at ondir (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:188:17)
    at load (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:69:43)
    at onex (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:92:31)
    at /home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

gulpfile.js

var   gulp          = require('gulp'),
      babel         = require('gulp-babel'),
      sourcemaps    = require('gulp-sourcemaps'),
      concat        = require('gulp-concat'),
      browserify    = require('browserify'),
      babelify      = require('babelify'),
      source        = require('vinyl-source-stream'),
      gulpBrowser   = require('gulp-browserify');

gulp.task('default', function(){
  return gulp.src('src/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(babel({
      presets: ['es2015']
    }))
    .pipe(concat('all.js'))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('dist'));
});

gulp.task('build', function(){
    return gulp.src('./dist/all.js')
      .pipe(gulpBrowser({
        debug:true,
        transform: ['babelify']
      }))
      .pipe(gulp.dest('bundle/compile.js'))
});

all.js

'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _log = require('log');

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var jet = function () {

  /**
   * Jet constructor
   * @param     {String} container - Html container identifier
   * @constructor
   **/

  function jet(container) {
    _classCallCheck(this, jet);

    /**
     * Jet container
     * @type    {HTMLElement}
     * @private
     **/
    this._container = document.getElementById(container);

    /**
     * Logger de la clase
     * @type    {Logger}
     * @private
     **/
    this._logger = new _log.Logger('Bullet');
  }

  _createClass(jet, [{
    key: 'showInfo',


    /**
     * Shows info in the console
     * @param {String} text - Info message
     **/
    value: function showInfo(text) {
      this._logger.log(text);
    }
  }]);

  return jet;
}();

;
'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var logger = function () {

  /**
   * Logger constructor
   * @param {String} channel - Logger channel
   * @constructor
   **/

  function logger(channel) {
    _classCallCheck(this, logger);

    /**
     * Logger channel
     * @type    {String}
     * @private
     **/
    this._channel = channel;

    /**
     * Private channel
     * @type    {String}
     * @private
     **/
    this._privateChannel = '[' + channel + ']';
  }

  /**
   * Shows a message in the console
   * @type    {String}
   * @private
   **/


  _createClass(logger, [{
    key: 'log',
    value: function log(text) {
      console.log(this._privateChannel + ' ' + text);
    }
  }]);

  return logger;
}();
//# sourceMappingURL=all.js.map

1 个答案:

答案 0 :(得分:1)

从我的观点来看,all {j} log处的包var _log = require('log');似乎不见了。你确定它已经安装好了吗?如果不是,您可能希望使用npm install --save log

进行安装