this.util.TextEncoder is not a constructor only in electron app (works in chrome)

THE SOLUTION

i previously had

wasm.setWasmPaths("./wasm/");
tf.setBackend("wasm").then(() => {
  //some simple vanilla js code
});

in my main code, and i have copied the folder from wasm(dist/) to project's folder.

Deleting the same from my project's folder and changing the code to -

wasm.setWasmPaths("../node_modules/@tensorflow/tfjs-backend-wasm/dist/"); //or start from ./ if your main file is in same folder as node_modules
tf.setBackend("wasm").then(() => {
  //...
});

How i recahed here?

at first thanks to @edkeveked for his effort and pointing me to

Error loading TensorflowJS in Electron App (Nodejs)

i got the solution by creating an electron hello world project and then adding tfjs, then tfjs-backend-wasm. the new project is working correctly but however even moving the node_modules from new project to older one is not working for the older. but as soon i changed the wasm path, it worked giving no error.

Update:

now I have encountered the problem several times and everytime it's solved by creating a new folder, first installing electron and creating a simple electron app first, and then installing other dependencies and copying old code in the new folder.(warning: don't copy the node modules folder)

It seems to be a bug in tfjs or electron