Giter VIP home page Giter VIP logo

Comments (12)

rmarscher avatar rmarscher commented on July 21, 2024 1

This is an issue with the bundler and not necessarily node-uuid. However, node-uuid could solve it by having an alternate entry point when the package is required in a browser context by using the "browser" key in package.json. See https://github.com/crypto-browserify/randombytes for an example on how to do that. The bundlers aren't smart enough to see that 'crypto' and Buffer are only used conditionally if the window global is defined.

With the current version of node-uuid, you can prevent from bloating your bundle with browserify or other bundlers by configuring them bundler to ignore or shim 'crypto' and 'Buffer' to empty objects. The conditionals in node-uuid don't use them if the window global exists anyway. Modern browsers offer window.crypto or window.msCrypto which node-uuid will use instead and then fall back to a built-in random number generator if the browser doesn't supply a crypto library.

In browserify, you can use --ignore or b.ignore() to ignore the 'crypto' and 'buffer' packages. I believe webpack has an IgnorePlugin that works similarly.

from uuid.

kenany avatar kenany commented on July 21, 2024

Just ran into this as well. Looks like that commit hasn't been published to npm yet. There hasn't been a publish in almost a year.

$ npm info node-uuid time

{ modified: '2013-12-28T11:49:54.162Z',
  created: '2012-02-06T13:13:29.968Z',
  '1.3.3': '2012-02-06T19:00:02.414Z',
  '1.2.0': '2012-02-06T18:37:58.432Z',
  '1.3.0': '2012-02-06T18:43:49.454Z',
  '1.3.1': '2012-02-06T18:46:09.071Z',
  '1.3.2': '2012-02-06T18:49:48.386Z',
  '1.1.0': '2012-02-06T18:54:52.771Z',
  '1.0.0': '2012-02-06T18:56:53.955Z',
  '1.4.0': '2012-10-18T13:51:34.289Z',
  '1.4.1': '2013-08-17T12:51:06.146Z' }

from uuid.

ianwremmel avatar ianwremmel commented on July 21, 2024

Also having an issue with this. The bigger problem is that rng.js doesn't seem to be compatible with Firefox or Safari because window.crypto.getRandomValues breaks when a shimmed Buffer is passed into it.

I'm able to solve the problem by changing line 25 of rng.js from

var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array

to

var bytes = new Uint8Array(size); //in browserify, this is an extended Uint8Array

Unfortunately, I can't find a way to do this with Browserify or by monkey-patching - editing the file directly is the only solution (which clearly isn't ideal or sustainable).

from uuid.

ianwremmel avatar ianwremmel commented on July 21, 2024

Follow up: that's rng.js in https://github.com/dominictarr/crypto-browserify. Technically, the problem I'm seeing is a bug there, but it can probably be fixed by preventing node-uuid from shimming crypto.

from uuid.

ianwremmel avatar ianwremmel commented on July 21, 2024

After further research, node-uuid doesn't seem to shim crypto or Buffer directly, but if crypto or Buffer is shimmed by another module, it will probably break node-uuid.

from uuid.

ben-ng avatar ben-ng commented on July 21, 2024

@ianwremmel did you settle on a solution for this problem? i'm running into it too.

from uuid.

ianwremmel avatar ianwremmel commented on July 21, 2024

I found the other places that were shimming Buffer and removed them. If nothing else shims Buffer, node-uuid won't shim it; if it's not available, node-uuid works just fine.

Avoiding Buffer is probably a good general guideline anyway. The Buffer shim is rather large and there's usually only a very small change need to avoid using it.

from uuid.

vvo avatar vvo commented on July 21, 2024

I fixed this is the "uuid" npmjs package (which is not this current repository, lulz) like this: defunctzombie@a33d3e0

from uuid.

slorber avatar slorber commented on July 21, 2024

thanks @vvo

So we have to do npm install uuid instead of npm install node-uuid right? Does it solve the @ianwremmel problem is Firefox? I have it too

from uuid.

slorber avatar slorber commented on July 21, 2024

So yes, in my case updating to package uuid in last version solved this error for me:
TypeError: Argument 1 of Crypto.getRandomValues does not implement interface ArrayBufferView.

from uuid.

vvo avatar vvo commented on July 21, 2024

great!

from uuid.

coolaj86 avatar coolaj86 commented on July 21, 2024

Is this still an issue?

from uuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.