[英]Gulp with browserify: Cannot find start module
I have pretty much the exact same problem as described in Gulp with browserify: Cannot find module src/js/main.js : I have a JavaScript project that I can build using browserify from the command line, but not in gulp. 我几乎有与Gulp中用browserify描述的完全相同的问题:找不到模块src / js / main.js :我有一个JavaScript项目,可以从命令行使用browserify来构建,但不能在gulp中构建。 But the solution for that question does not work for me.
但是,该问题的解决方案对我不起作用。
From the command line: 在命令行中:
browserify -t reactify ./js/inspector > static/js/inspector.js
works perfectly. 完美地工作。 When I run the following gulp task:
当我运行以下gulp任务时:
gulp.task('browserify', function() {
return browserify({
transform: ['reactify'],
entries: ['./js/inspector.js']
})
.bundle()
.pipe(source('inspector.js'))
.pipe(gulp.dest('./static/js/'));
});
and run it, I get the following error in the console: 并运行它,我在控制台中收到以下错误:
Error: Cannot find module '../../inspector'
and also the generated file has the same length as the CLI file but not the same order of modules. 并且生成的文件与CLI文件的长度相同,但模块的顺序不同。 Which puzzles me.
这让我感到困惑。
I have the same version of browserify in my global and local modules, and I've not knowingly configured it, anywhere. 我的全局和本地模块中具有相同版本的browserify,但我没有在任何地方有意识地对其进行配置。
Unlike Ben Davis, who asked the other question, adding a ./ to the start of my path changes nothing. 与本·戴维斯(Ben Davis)提出另一个问题不同,在路径的开头添加./不会改变任何内容。
I don't understand why browserify gives a different, and broken, output, when run through gulp. 我不明白为什么在通过gulp运行时browserify会给出不同的,破碎的输出。
Update: The directory structure of the project: 更新:项目的目录结构:
gulpfile.js
node_modules/
js/ (also contains subdirectories with JS code)
inspector.js
static/
js/
inspector.js (built)
Update: When I run Browserify through Grunt, I also get a different file, but it works. 更新:当我通过Grunt运行Browserify时,我也得到了一个不同的文件,但是它可以工作。
You can try wrapping your return function in an IIFC. 您可以尝试将返回函数包装在IIFC中。
//======================================
// Task: browserify
//======================================
gulp.task('browserify', function() {
return (function() {
browserify(config.src)
.bundle()
.pipe(source(config.name))
.pipe(gulp.dest(config.dest));
})();
});
I am using the above successfully in a current proj. 我在当前项目中成功使用了以上内容。
I had other modules that required the root module, à la: 我还有其他需要根模块的模块,例如:
var inspector = require('../../inspector');
This is what caused the problem (somehow). 这是导致问题的原因(以某种方式)。 Putting in a root module that was never required by anything else made gulp + browserify work without any problems.
放入根本不需要的根模块,使得gulp + browserify可以正常工作。
I'll see if I can create a minimal reproduction project for the gulp / browserify maintainers. 我将看看是否可以为gulp / browserify维护者创建一个最小的复制项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.