Browserify + babelify找不到模块
您好我试图将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)
链接地址: http://www.djcxy.com/p/5643.html