browserify错误'未捕获TypeError:undefined不是函数'

时间:2014-07-28 15:50:08

标签: javascript jquery node.js browserify

在参考这个问题(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;
};

1 个答案:

答案 0 :(得分:3)

一般情况下,您cannot access the file system使用Browserify,因为没有文件系统可供访问(请记住,您在网络上运行此功能,而不仅仅是您的计算机)。

但是,您可以使用brfs module

内联文件内容
相关问题