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

ReferenceError: atob is not defined In nodejs #65

Closed
davidyuk opened this issue Jun 5, 2021 · 3 comments
Closed

ReferenceError: atob is not defined In nodejs #65

davidyuk opened this issue Jun 5, 2021 · 3 comments

Comments

@davidyuk
Copy link

davidyuk commented Jun 5, 2021

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

const text = atob(base64);

@antelle
Copy link
Owner

antelle commented Jun 5, 2021

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
Copy link
Author

davidyuk commented Jun 5, 2021

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 antelle closed this as completed in 111cc39 Jun 5, 2021
@antelle
Copy link
Owner

antelle commented Jun 5, 2021

Added the fallback, thanks

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