用babelify + browserify使用gulp无法找到模块
我试图用gulp
改造我的JavaScript代码ecm6
到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
从我的角度来看,包的log
在all.js var _log = require('log');
似乎失踪了。 你确定它已安装吗? 如果不是,您可能需要使用npm install --save log
进行npm install --save log
上一篇: Using gulp with babelify + browserify cannot find module
下一篇: I cannot install underscore in npm. Get the following error