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

Cannot access "events.EventEmitter" in client code #147

Closed
Kazturin opened this issue Oct 9, 2023 · 4 comments
Closed

Cannot access "events.EventEmitter" in client code #147

Kazturin opened this issue Oct 9, 2023 · 4 comments
Labels

Comments

@Kazturin
Copy link

Kazturin commented Oct 9, 2023

Hi.
error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code

@pokusew
Copy link
Owner

pokusew commented Oct 9, 2023

Hi @Kazturin,

Thank you for posting your issue here. 👍

It looks like a problem with your setup. Where are you trying to run nfc-pcsc? What build tools / bundlers are you using?

First, please note that nfc-pcsc can be used only in Node.js (either Node.js directly or in Electron.js).
nfc-pcsc cannot be used directly in browsers.

Second, make sure you correctly set up any build tools or bundlers (webpack, Rollup, Vite, etc.) you use to target Node.js and not to attempt to make it browser-compatible.

Hope it helps. Let me know. 🙂

@pokusew pokusew changed the title module Cannot access "events.EventEmitter" in client code Oct 9, 2023
@Kazturin
Copy link
Author

Hi @Kazturin,

Thank you for posting your issue here. 👍

It looks like a problem with your setup. Where are you trying to run nfc-pcsc? What build tools / bundlers are you using?

First, please note that nfc-pcsc can be used only in Node.js (either Node.js directly or in Electron.js). nfc-pcsc cannot be used directly in browsers.

Second, make sure you correctly set up any build tools or bundlers (webpack, Rollup, Vite, etc.) you use to target Node.js and not to attempt to make it browser-compatible.

Hope it helps. Let me know. 🙂

Hi pokusew.
Thanks a lot. I didn't expect such a quick response :)
Windows 10 OS, using vite builder, node v18.18

If I clone the project https://github.com/pokusew/nfc-pcsc.git and run it, then this error occurs:
Screenshot_9

@pokusew
Copy link
Owner

pokusew commented Oct 10, 2023

Hi @Kazturin,

Thank you for the details you provided.

First, I've just fixed the error you encountered while cloning and running the example (npm run example). Thank you for posting the screenshot here. 👍 The error was affecting only some of the examples (so, for example, npm run example-uid-logger worked). Nevertheless, everything should work now after the fix.
Can you please try again and let me know if it works for you now? Just to be sure, please delete the directory with the cloned repo, clone it again, run npm install, and finally try npm run example.

Second, you mentioned you use Vite in your project.
Note that nfc-pcsc can be used only in Node.js (either Node.js directly or in Electron.js).
Your Vite setup is probably the reason you see the error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.
I think that you need to appropriately set the build.target in Vite's build options. Probably to something like node18.

Hope it helps. Let me know. 🙂

@Kazturin
Copy link
Author

Thanks @pokusew , the examples run without errors.

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

No branches or pull requests

2 participants