`ReferenceError: atob is not defined` In nodejs
davidyuk opened this issue · 3 comments
davidyuk commented
Thanks for solving the previous issue!
$ node
Welcome to Node.js v14.16.0.
Type ".help" for more information.
> const { hash } = require('argon2-browser/dist/argon2-bundled.min')
undefined
> hash({ pass: 'password', salt: 'somesalt' })
Promise { <pending> }
> (node:10078) UnhandledPromiseRejectionWarning: ReferenceError: atob is not defined
at /.../argon2-browser/dist/argon2-bundled.min.js:1:8174
at /.../argon2-browser/dist/argon2-bundled.min.js:1:8283
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
argon2-browser version is 1.18.0
Seems that atob
is not available in node, but it is used in
Line 97 in 63cda65
antelle commented
You can either upgrade your node.js to get atob
working, or bundle a polyfill if you need to redistribute the library for older node.js.
davidyuk commented
According to https://nodejs.org/ node@14 is still LTS version, I think it should be supported by default. atob
can be easily replaced with Buffer
in node. I was going to sent a PR with something like:
function decodeWasmBinary(base64) {
+ if (typeof Buffer === 'function') {
+ return new Uint8Array(Buffer.from(base64, 'base64'))
+ }
const text = atob(base64);
const binary = new Uint8Array(new ArrayBuffer(text.length));
for (let i = 0; i < text.length; i++) {
binary[i] = text.charCodeAt(i);
}
return binary;
}
but can't check it because of #66
antelle commented
Added the fallback, thanks