Browserify + babelify cannot find module

Hi I'm trying to transform js code into something that browser can execute.

utils/Logger.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; }; }();

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

/**
 *
 * Logger class
 **/

var Logger = function () {

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

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

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

  _createClass(Logger, [{
    key: 'log',


    /**
     * Log text
     * @param {String} text - String to print
     **/
    value: function log(text) {
      console.log('[' + this._channel + ']' + text);
    }
  }]);

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

jet.js

'use strict';

require('./utils/Logger');

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

/**
 * Jet Framework main class
 **/

var jet =

/**
 * Jet constructor
 * @param   {String} element
 **/
function jet(element) {
  _classCallCheck(this, jet);

  /**
   * Element html layer
   * @type    {HTMLElement}
   * @private
   **/
  this._element = document.getElementById(element);

  /**
   * Logger instance
   * @type    {Logger}
   * @private
   **/
  this._logger = new Logger(this.channel);
};

;

/**
 * Channel constant
 * @type    {String}
 * @const
 **/
jet.prototype.channel = 'JET';
//# sourceMappingURL=jet.js.map

Description

When I put this jet.js inside a browser it gives the following error:

Uncaught ReferenceError: require is not defined

I read a question here and I decided to use browserify + babelify combo. When I introduce in the terminal the next command, it shows a dependency error.

What am I doing wrong? What do I need to run this properly?

Jaster.

Command

browserify dist/src/jet.js -o out/bundle.js -t [ babelify --presets [ es2015 react ] ]

Output

Error: Cannot find module './utils/Logger' from '/home/ismael/projects/js-evolve/es-2015/dist/src'
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:55:21
    at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)
链接地址: http://www.djcxy.com/p/5644.html

上一篇: 使用Browserify和Uglify与Babelify

下一篇: Browserify + babelify找不到模块