Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.0.4 has broken change #154

Closed
legokichi opened this issue Feb 9, 2017 · 5 comments
Closed

5.0.4 has broken change #154

legokichi opened this issue Feb 9, 2017 · 5 comments

Comments

@legokichi
Copy link

legokichi commented Feb 9, 2017

// fileA.js
const Buffer = require("buffer/").Buffer;
module.exports.A = new Buffer(10);
// fileB.js
const Buffer = require("buffer/").Buffer;
module.exports.B = new Buffer(10);
// fileC.js
const {A} = require("./fileA");
const {B} = require("./fileB");
console.log(Buffer.concat([A, B]));

in 5.0.3

$ browserify fileC.js > fileD.js | node
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>

in 5.0.4

$ browserify fileC.js > fileD.js | node
[stdin]:472
      throw new TypeError('"list" argument must be an Array of Buffers')
      ^

TypeError: "list" argument must be an Array of Buffers
    at Function.concat ([stdin]:472:13)
    at Object.<anonymous> ([stdin]:1917:20)
    at Object.6../fileA ([stdin]:1919:4)
    at s ([stdin]:1:254)
    at e ([stdin]:1:425)
    at [stdin]:1:443
    at ContextifyScript.Script.runInThisContext (vm.js:25:33)
    at Object.exports.runInThisContext (vm.js:77:17)
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (module.js:556:32)
@legokichi legokichi reopened this Feb 9, 2017
@feross
Copy link
Owner

feross commented Feb 9, 2017

@legokichi What version of browserify are you using? I tested with browserify v14 and could not reproduce the issue. Closing until enough info to reproduce is provided.

@feross feross closed this as completed Feb 9, 2017
@feross
Copy link
Owner

feross commented Feb 9, 2017

Nevermind -- reinstalling browserify (which pulls in the latest buffer) and I can repro this now.

@feross feross reopened this Feb 9, 2017
@feross
Copy link
Owner

feross commented Feb 9, 2017

It turns out that it's not possible to use instanceof Buffer safely, like I thought.

It's not possible to use instanceof Buffer reliably in a browserify context because there could be multiple different copies of the 'buffer' package in use.

This previous method (checking buf._isBuffer) works even for Buffer instances that were created from another copy of the buffer package.

NOTE: It's possible to have two different "instances" of the 'buffer' package, even if the 'buffer' package appears only once in the bundled code. This can happen if you require 'buffer' in different ways, for example:

require('buffer') vs. require('buffer/') vs. using the implicit Buffer global.

You can confirm this by browserifying this code:

console.log(require('buffer').Buffer === require('buffer/').Buffer) // will be false

So, for this reason, instanceof won't work.

@feross
Copy link
Owner

feross commented Feb 9, 2017

Released as 5.0.5.

@legokichi
Copy link
Author

thanks a lot 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants