utf8.js
utf8.js copied to clipboard
string.charCodeAt is not a function
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
Are you passing undefined
to utf8.decode()
? If not, how can I reproduce this issue?
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.
Reading the file with encoding set fixes this problem:
const input = fs.readFileSync('./thefile.txt', {encoding: 'utf8'});
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.