Browserify + babelify找不到模块

时间:2016-06-23 15:09:35

标签: javascript node.js browserify grunt-babel

您好我试图将js代码转换为浏览器可以执行的内容。

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

描述

当我将此jet.js放入浏览器时,会出现以下错误:

Uncaught ReferenceError: require is not defined

我在这里阅读了一个问题,我决定使用browserify + babelify组合。当我在终端中引入下一个命令时,它显示了依赖性错误。

我做错了什么?我需要什么才能正确运行?

雅斯特尔。

命令

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

输出

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)

0 个答案:

没有答案