microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.43k stars 232 forks source link

No loader is configured for ".node" files (vite & tauri) #566

Closed AviAvinav closed 1 year ago

AviAvinav commented 1 year ago

Environment details

Issue description

I am trying to use node-pty with vite (react) and tauri. I have been running into the following error:

X [ERROR] No loader is configured for ".node" files: node_modules/node-pty/build/Release/pty.node

Is there a way I can fix this, I looked into a similar issue and found a solution for vue: https://github.com/microsoft/node-pty/issues/435#issuecomment-715502116, how can I do this in vite?

daniel-brenot commented 1 year ago

The issue here is that you are trying to load a native module from a browser context. This isn't possible, and i believe using this in the context of tauri isn't quite the way to go. I suggest using rust code to do this using some available libraries since you are using tauri. Alternatively you may be able to sideload node.js, and if so you could use this library from that context.

The reason this works in electron is that electron has front end code as well as backend code. The backend code is run by node.js, while the frontend code runs in a browser context. With tauri it's a similar thing, but the backend is rust by default.

Tyriar commented 1 year ago

Also I'll add that this is generally discouraged in Electron as well as sandboxed renderers are better for both security and performance.