javascript - 浏览器错误 'Uncaught TypeError: undefined is not a function '

标签 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;
};

最佳答案

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

但是,您可以使用 brfs module 内联文件内容.

关于javascript - 浏览器错误 'Uncaught TypeError: undefined is not a function ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24999068/

相关文章:

javascript - 带有 Chrome 的 CORS XSL

jquery - 如何从此链接获取json数据

javascript - 使用 javascript(或 jQuery)选择和操作 CSS 伪元素,例如::before 和::after

javascript - 使用存储查找字符串的数组和存储替换字符串的数组替换文件中的字符串

node.js - 从 mongoose 数据库获取模型

node.js - 收到付款后如何执行功能(Sofort)?

javascript - 我无法将数据从 Controller 传递到 Sencha Touch 2.4 中的 View

javascript - 如何在将鼠标悬停在按钮上时将背景图像更改为另一个图像?

javascript - 单击按钮一次显示一个列表

jquery - select2 - 初始化选择错误