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

string.charCodeAt is not a function

Open bash0312 opened this issue 7 years ago • 4 comments

TypeError: string.charCodeAt is not a function
    at ucs2decode (C:\Users\bash\NEMid\node_modules\utf8\utf8.js:30:19)
    at Object.utf8decode [as decode] (C:\Users\bash\NEMid\node_modules\utf8\utf8.js:201:15)
    at Object.<anonymous> (C:\Users\bash\NEMid\client.js:21:95)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.runMain (module.js:607:10)
    at run (bootstrap_node.js:382:7)

node v7.0.0

bash0312 avatar Mar 04 '17 20:03 bash0312

Are you passing undefined to utf8.decode()? If not, how can I reproduce this issue?

mathiasbynens avatar Mar 04 '17 22:03 mathiasbynens

I also encountered this error and was at first a bit confused, but then realised that it was happening because I was passing a Buffer instead of a "binary string". Maybe the docs can be made more explicit about the fact that Buffer are actually not supported at least not until https://github.com/mathiasbynens/utf8.js/issues/7 is solved.

hellais avatar Aug 13 '17 20:08 hellais

Reading the file with encoding set fixes this problem:

const input = fs.readFileSync('./thefile.txt', {encoding: 'utf8'});

jmaister avatar Aug 01 '18 15:08 jmaister

Reading the file with encoding set fixes this problem: const input = fs.readFileSync('./thefile.txt', {encoding: 'utf8'});

If you are reading the file in that way, then you do not need this library.

hellais avatar Aug 01 '18 16:08 hellais