Using gulp with babelify + browserify cannot find module

I tried to use gulp to transform my javascript code in ecm6 to ecm5 and it was ok. gulp-babel added require inside the transformed code, and now I need to use this code in a browser and it's necessary browserify the code.

When I run this command in a terminal, it shows me the following error:

What can I do to solve this? What am I doing wrong?

PD: Thanks for the help.

Jaster

Command

gulp build

Output

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

From my point of view the package log at all.js var _log = require('log'); seems to be missing. Are you sure that it is installed? If not you might want to install it using npm install --save log

链接地址: http://www.djcxy.com/p/33018.html

上一篇: 当我尝试使用离子启动新应用程序时,msg.trim不是函数

下一篇: 用babelify + browserify使用gulp无法找到模块