Skip to content

Instantly share code, notes, and snippets.

@deathcap
Last active August 29, 2015 14:15
Show Gist options
  • Save deathcap/898bec7260a0b0dbf5cd to your computer and use it in GitHub Desktop.
Save deathcap/898bec7260a0b0dbf5cd to your computer and use it in GitHub Desktop.
browserifying node-minecraft-protocol yggdrasil auth -> superagent -> mime, fs.readFileSync mime type reading error
try.js:
var mime = require('mime');
browserify try.js > b.js
<script src="b.js"></script>
Uncaught TypeError: undefined is not a function
b.js:2621 module.exports.load
b.js:2662 (anonymous function)
b.js:2670 20.fs
b.js:1 s
b.js:1 (anonymous function)
b.js:1094 9../utils
b.js:1 s
b.js:1 (anonymous function)
b.js:209 (anonymous function)
b.js:1031 4../agent
b.js:1 s
b.js:1 (anonymous function)
b.js:2940 (anonymous function)
b.js:2954 23.mime
b.js:1 s
b.js:1 e
b.js:1 (anonymous function)
/**
* Load an Apache2-style ".types" file
*
* This may be called multiple times (it's expected). Where files declare
* overlapping types/extensions, the last file wins.
*
* @param file (String) path of file to load.
*/
load: function(file) {
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'), // <-- *** crashes here, no fs.readFileSync
file = "/node_modules/superagent/node_modules/mime/types/mime.types"
fs.readFileSync unavailable in browserify
except for constant literal paths with https://github.com/substack/brfs, but this path is not "constant"
can it be made so?
called from:
// Load our local copy of
// http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
mime.load(path.join(__dirname, 'types/mime.types'));
// Overlay enhancements submitted by the node.js community
mime.load(path.join(__dirname, 'types/node.types'));
mime 1.3.4
superagent 0.10.0 uses mime 1.2.5
lib/node/part.js
var utils = require('./utils')
, Stream = require('stream').Stream
, mime = require('mime')
browserifying superagent:
var superagent = require('superagent');
global.superagent = superagent;
console.log('about to post');
superagent.post('http://cors.maxogden.com/')
.type('json')
.send({k: "v"})
.end(function (resp) {
console.log(resp);
});
same crash
superagent has browser support in lib/client.js (uses XMLHttpRequest), why isn't it being used?
is it supposed to be? superagent/package.json doesn't have a "browser" field
[not that it would work in browserified node-minecraft-protocol anyway - or more specifically,
the yggdrasil auth https://github.com/PrismarineJS/prismarine-yggdrasil - as it contacts
https://authserver.mojang.com, which is not CORS-enabled (and probably won't be).]
see also:
superagent vs https://github.com/request/request?
http://nodejs.org/api/http.html + https://www.npmjs.com/package/http-browserify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment