I am attempting to run a set of files, and this error keeps popping up. I ran a separate set of files, loading a rest API to my localhost and that worked without error, but switching back to the first set of files still ends in the follow error:
const utf8Encoder = new TextEncoder();
^
ReferenceError: TextEncoder is not defined
at Object.<anonymous> (devel/node_modules/whatwg-url/dist/encoding.js:2:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (devel/node_modules/whatwg-url/dist/url-state-machine.js:5:34)
at Module._compile (internal/modules/cjs/loader.js:778:30)
I have attempting to reinstall node.js, as well as update and manually delete the modules that are calling for this TextEncoder. The differences in required modules includes 'mongodb' and and 'csv-parse', which were on my personal machine, but not my office machine. Before I 'npm install ...' these two modules, the error appeared, so I then install the two modules, yet the error still persists. I also updated nodejs and again the error was the same. Any ideas on how to fix this so I can run my code?
I figured it out, it had to do with my mongodb and node_modules unbalanced connectivity, where I went to `/node_modules/whatwg-url/dist/encoding.js and imported the libraries for the TectEncoder and Text Decoder. The other way this can be fixed is at the top of the files using mongodb, insert...
global.TextEncoder = require("util").TextEncoder; global.TextDecoder = require("util").TextDecoder;
Either way fixes the compatibility issue.