mathiask88 / node-snap7

node.js wrapper for snap7
MIT License
166 stars 59 forks source link

Uncaught Error: Dynamic require of “events” is not supported #95

Open JangTaewan opened 1 year ago

JangTaewan commented 1 year ago

Hello,

I’m using your node-snap7 package in a Vite project and I’ve encountered an issue. When I try to run my project, I get the following error:

Uncaught Error: Dynamic require of "events" is not supported at chunk-6NOISVLF.js?v=2f01d05e:10:9 at node_modules/.vite-electron-renderer/events.mjs (events.mjs:1:50) at __init (chunk-6NOISVLF.js?v=2f01d05e:13:56) at node_modules/node-snap7/lib/node-snap7.js (node-snap7.js:6:14) at __require2 (chunk-6NOISVLF.js?v=2f01d05e:16:50) at node-snap7.js:59:78

It seems like the issue is related to the dynamic require of “events”. I understand that Vite prefers ES6 import syntax over CommonJS require, which might be causing this issue.Do you know any solutions to this problem?Thank you for your time and for the work you’ve put into this package.

YungShadi commented 12 months ago

Hi, did you solve this problem? I'm getting same error in my project on electron+vite+react, when trying to add Discord-rpc package.

Error: Dynamic require of "events" is not supported at chunk-AUZ3RYOM.js?v=5aa5806a:12:9 at node_modules/.vite-electron-renderer/events.mjs (events.mjs:1:50) at init (chunk-AUZ3RYOM.js?v=5aa5806a:15:56) at node_modules/discord-rpc/src/client.js (client.js:3:22) at __require2 (chunk-AUZ3RYOM.js?v=5aa5806a:18:50) at node_modules/discord-rpc/src/index.js (index.js:6:11) at require2 (chunk-AUZ3RYOM.js?v=5aa5806a:18:50) at index.js:10:1

I'v tried to fix this be converting all require statements to import inside node_modules, but this dose not seem to be the case, because when i use debugger to inspect files in browser they are still require statements.

JangTaewan commented 12 months ago

Hi, did you solve this problem? I'm getting same error in my project on electron+vite+react, when trying to add Discord-rpc package.

Error: Dynamic require of "events" is not supported at chunk-AUZ3RYOM.js?v=5aa5806a:12:9 at node_modules/.vite-electron-renderer/events.mjs (events.mjs:1:50) at init (chunk-AUZ3RYOM.js?v=5aa5806a:15:56) at node_modules/discord-rpc/src/client.js (client.js:3:22) at __require2 (chunk-AUZ3RYOM.js?v=5aa5806a:18:50) at node_modules/discord-rpc/src/index.js (index.js:6:11) at require2 (chunk-AUZ3RYOM.js?v=5aa5806a:18:50) at index.js:10:1

I'v tried to fix this be converting all require statements to import inside node_modules, but this dose not seem to be the case, because when i use debugger to inspect files in browser they are still require statements.

Hi, I think the cause of this issue is that the browser does not support Node’s core modules.Try the vite-plugin-node-polyfills package.Another package, nodes7, works fine after I added the vite-plugin-node-polyfills package, but node-snap7 still does not.