antelle / argon2-browser

Argon2 library compiled for browser runtime
https://antelle.net/argon2-browser
MIT License
367 stars 79 forks source link

ReferenceError: TextEncoder is not defined #29

Closed 382303784 closed 4 years ago

382303784 commented 4 years ago

I have encountered some problems while using it.


//first
npm install argon2-browser

//code
const argon2 = require("argon2-browser");
const _hash = await argon2.hash({
        pass:'password',
        salt: "salt"
    });

//result
ReferenceError: TextEncoder is not defined
ReferenceError: TextEncoder is not defined

E:\work\czr-remix-ide\czr\czr_account.js\node_modules\argon2-browser\dist\argon2.js:1
(function (exports, require, module, __filename, __dirname) { var Module=typeof self!=="undefined"&&typeof self.Module!=="undefined"?self.Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=function(status,toThrow){throw toThrow};Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONME
abort(ReferenceError: TextEncoder is not defined). Build with -s ASSERTIONS=1 for more info.
382303784 commented 4 years ago

I have encountered some problems while using it.

//first
npm install argon2-browser

//code
const argon2 = require("argon2-browser");
const _hash = await argon2.hash({
        pass:'password',
        salt: "salt"
    });

//result
ReferenceError: TextEncoder is not defined
ReferenceError: TextEncoder is not defined

E:\work\czr-remix-ide\czr\czr_account.js\node_modules\argon2-browser\dist\argon2.js:1
(function (exports, require, module, __filename, __dirname) { var Module=typeof self!=="undefined"&&typeof self.Module!=="undefined"?self.Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=function(status,toThrow){throw toThrow};Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONME
abort(ReferenceError: TextEncoder is not defined). Build with -s ASSERTIONS=1 for more info.

Code is part of the code

ms140569 commented 4 years ago

I do have this problem with the examples as well:

examples/node/argon2-demo-node.js

afrancht commented 4 years ago

Are you using React?

ms140569 commented 4 years ago

No, not at all...

382303784 commented 4 years ago

Are you using React?

no

antelle commented 4 years ago

Hi! TextEncoder was added in node.js 11: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V11.md Added support for old node.js as well.