warcio.js icon indicating copy to clipboard operation
warcio.js copied to clipboard

Node JS: crypto import polyfill not taken into account?

Open matteocargnelutti opened this issue 2 years ago • 2 comments

Hi there 👋 !

I see that there is now a polyfill to automatically import and declare crypto in the global scope.

Unfortunately, I'm getting the following error when using WARCRecord.create() after removing my own global import of crypto :

ReferenceError: crypto is not defined

For reference, I'm importing crypto as such to compensate for its absence:

import crypto from 'crypto'
global.crypto = crypto

I'm using warcio.js 2.0.1 with Node 18+.

Thanks in advance,

matteocargnelutti avatar Dec 17 '22 14:12 matteocargnelutti

Yes, the current polyfill applies only to the test suite. I was having trouble setting up a proper polyfill for the node build. Though, Node 18 does have --experimental-global-webcrypto for making crypto global and I guess in node 19, this is the default..

ikreymer avatar Dec 19 '22 18:12 ikreymer

Finally found a way to have automatic polyfills:

Use inject with a separate polyfills file

jlarmstrongiv avatar May 01 '23 03:05 jlarmstrongiv