简体   繁体   English

browserify错误“未捕获的TypeError:未定义不是函数”

[英]browserify error 'Uncaught TypeError: undefined is not a function '

In reference to this question ( browserify 'Error: Cannot find module' in trying to fix 'Uncaught reference error: require is not defined' ), I got the browserify command to work thanks to stackoverflow community, however, I got another error that tells me 关于这个问题( 在尝试修复“未捕获的引用错误:未定义”时browserify'错误:找不到模块' ),由于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

I believe the function it is complaining about is the 'fs.readFileSync' function. 我相信它抱怨的功能是“ fs.readFileSync”功能。 Here is the line 10786 in my 'bundle.js' file 这是我的'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;
};

In general, you cannot access the file system using Browserify since there's no file system for it to access (remember, you're running this on the web, not just your computer). 通常,您无法使用Browserify 访问文件系统,因为没有文件系统可供访问(请记住,您正在网络上运行此文件,而不仅仅是在计算机上运行)。

However, you can inline the contents of files using the brfs module . 但是,您可以使用brfs模块内联文件的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:未捕获的类型错误:未定义不是函数 - Error: Uncaught TypeError: undefined is not a function 函数错误:未捕获TypeError:未定义不是函数 - Function error: Uncaught TypeError: undefined is not a function Nodejs Browserify Uncaught TypeError:exists不是函数 - Nodejs Browserify Uncaught TypeError: exists is not a function browserify:-未捕获的TypeError:fs.​​readFileSync不是函数 - browserify :- Uncaught TypeError: fs.readFileSync is not a function 为什么会出现错误“未捕获的TypeError:未定义不是函数”? - Why is there an error, “Uncaught TypeError: undefined is not a function”? 为什么会出现错误“未捕获的TypeError:未定义不是函数”? - Why is there an error, “Uncaught TypeError: undefined is not a function”? dataTable引发错误未捕获的TypeError:未定义不是函数 - dataTable raise error Uncaught TypeError: undefined is not a function 模态错误-未捕获的TypeError:undefined不是函数模态 - Modal error - Uncaught TypeError: undefined is not a function modal 错误消息“Uncaught TypeError: undefined is not a function”(数据表) - Error message "Uncaught TypeError: undefined is not a function" (DataTable) Firebase上的“未捕获的TypeError:未定义不是函数”错误 - “Uncaught TypeError: undefined is not a function” error on firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM