简体   繁体   中英

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

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. Here is the line 10786 in my 'bundle.js' file

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).

However, you can inline the contents of files using the brfs module .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM