Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JangTaewan opened this issue Nov 24, 2023 · 2 comments
Open

Comments

@JangTaewan
Copy link

JangTaewan commented Nov 24, 2023

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
Copy link

YungShadi commented Dec 5, 2023

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants