gpt4 book ai didi

javascript - Stitch & Grunt——找不到文件

转载 作者:行者123 更新时间:2023-11-30 05:53:14 24 4
gpt4 key购买 nike

刚开始玩Grunt并想使用 Stitch组合我的模块以供客户端使用。总的来说,我对 commonJS 没有太多经验,而且这两个库对我来说都是新手——所以请多多包涵。

这是我的 Grunt 文件的摘录:

var fs     = require('fs');
var stitch = require('stitch');

module.exports = function(grunt) {

grunt.initConfig({

… SNIP …

stitch: {
dist: {
src: ['lib'],
dest: 'dist/<%= pkg.name %>.js'
}
}
});


grunt.registerMultiTask('stitch', 'Compile common.js modules with stitch', function() {
var done = this.async();

var paths = this.file.src.map(function(dir){
return __dirname + '/' + dir;
});

stitch.createPackage({ paths: paths }).compile(function(error, src){
if (error) {
return grunt.log.writeln(error);
}
file.write(name, src);
grunt.log.writeln("File '" + name + "' created.");
done();
});
});

};

然而,当运行 grunt stitch 时,我得到:

ReferenceError: can't compile  /path/to/file.js
file is not defined

虽然绝对路径是正确的,并且文件确实存在。

如有任何建议,我们将不胜感激。

最佳答案

事实证明,我尝试合并的其中一个文件中的引用不正确。

这个问题可能应该被关闭,因为过于本地化,但在不太可能的情况下,有人可能会遇到同样的问题 — 检查所有 require调用并查看它们是否指向正确的文件。请记住,该路径将是相对于根而不是所需文件的路径。

但是,这个错误消息尤其是非常隐晦且基本上无用的 IMO。

关于javascript - Stitch & Grunt——找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13513038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com