关于这个问题( browserify 'Error: Cannot find module' in trying to fix 'Uncaught reference error: require is not defined' ),感谢 stackoverflow 社区,我得到了 browserify 命令,但是,我收到了另一个错误,告诉我
Uncaught TypeError: undefined is not a function bundle.js:10786
Mime.load bundle.js:10786
(anonymous function) bundle.js:10822
_process bundle.js:10848
我相信它提示的函数是“fs.readFileSync”函数。这是我的“bundle.js”文件中的第 10786 行
Mime.prototype.load = function(file) {
this._loading = file;
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'), <---LINE 10786
lines = content.split(/[\r\n]+/);
lines.forEach(function(line) {
// Clean up whitespace/comments, and split into fields
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
map[fields.shift()] = fields;
});
this.define(map);
this._loading = null;
};
最佳答案
一般来说,您cannot access the file system使用Browserify,因为没有文件系统可供它访问(请记住,您是在网络上运行它,而不仅仅是在您的计算机上)。
但是,您可以使用 brfs module 内联文件内容.
关于javascript - 浏览器错误 'Uncaught TypeError: undefined is not a function ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999068/