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

"TextEncoder is not defined" error when running tests in Node 12.22.0 #15

Open
sshadmand opened this issue Dec 18, 2022 · 1 comment
Open

Comments

@sshadmand
Copy link

sshadmand commented Dec 18, 2022

Package installed

"dependencies": {
    ...
    "gpt-3-encoder": "^1.1.3",
    ...
}

When ran

    ReferenceError: TextEncoder is not defined 
      at Object.<anonymous> (node_modules/gpt-3-encoder/Encoder.js:21:21)

Which references: https://github.com/latitudegames/GPT-3-Encoder/blob/master/Encoder.js#L21

Suggestion: Potentially allow pass in for TextEncoder or change to NodeJS reco:

var util = require('util');
let encoder = new util.TextEncoder();
let uint8Array = encoder.encode("Hello");
console.log(uint8Array);
@sshadmand sshadmand changed the title Error when running tests in Node 12.22.0 "TextEncoder is not defined" error when running tests in Node 12.22.0 Dec 18, 2022
@sshadmand
Copy link
Author

sshadmand commented Dec 18, 2022

NodeJS compatible fork PR here: #16

syonfox pushed a commit to syonfox/gptoken that referenced this issue Dec 25, 2022
By using the Buffer class in this way, you can encode and decode strings as UTF-8 without using the TextEncoder and TextDecoder classes. This can be useful if you need to support earlier versions of Node.js that do not have these classes in the util module.
syonfox pushed a commit to syonfox/gptoken that referenced this issue Jan 7, 2023
…eaking change but i think its actually mor widely compatible and should be fine.
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

1 participant