-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Issue with React + Vite + SWC #270
Comments
I just created another project only react without SWC, and still have the same issue.
|
This is a clean installation of React using Vitejs. https://stackblitz.com/edit/vitejs-vite-mbxbcc?file=package.json,src%2FApp.tsx&terminal=dev @tiagosiebler this is probably a issue with vitejs configuration but would be great to have it working. |
This is useful, not done much experimentation with my SDKs in frontend projects but I do want to ensure it's working, so this gives me something to test with. It's probably dependencies that don't exist in the frontend, such as the event emitter. Will try to investigate this week. |
Hey @brlocky - made some progress here: Using the guidance from here: #258 Currently stuck on an exception from another dependency: "bybit-api.js?v=b7e7f7cf:1439 Uncaught TypeError: Cannot read properties of undefined (reading 'from')"
This is silly though...if I check the dependencies in this SDK for where safe-buffer is coming from, it's only dev dependencies:
Why is vite trying to build dev dependencies into the frontend module? |
that "from" smells buffer ! Thank you for your super investigation, I'll dig into other projects where i did had to add some alias, and now that i saw your test, i remembered to be something with crypto and buffers, I'll have a look latter on ! |
Interesting, I think I should start including the ts files with the published package. Seems when importing the ts resources directly, there's more control over what dependencies are pulled in and what modules are swapped for browser usage. Looks like I've gotten it working - let me publish a beta release of this SDK which includes the src/*ts files, and then we can see what else needs to be done to get this working properly with full type support! |
@brlocky this seems to work: I've had to include src/*ts in the beta version of the package. However, I'm not sure if this is the correct approach to properly support modern frontend projects and I'm sure there's a lot to improve (perhaps also in the way the package.json is configured for the SDK). Would love some help here, as I'm less experienced in the frontend space. |
Also note, I've had to add a buffer polyfill, but this seems weird as the only dependencies using buffer are dev dependencies from the SDK (such as ts-jest), which absolutely should not be included in the browser bundle. Also haven't tested websockets as I suspect that will need more changes for browser support (especially since EventEmitter is another nodejs package) |
I have it working locally, only changing the import, with version without need to change the Vite setup. https://stackblitz.com/edit/vitejs-vite-qybfvu?file=vite.config.ts,package.json,src%2FApp.tsx. |
I would think theres somehow a issue in the build, where js and ts are not having same exports. I spent sometime tweaking your build, but without success. |
oh interesting, so including the ts resources isn't necessary after all? |
Yup, I deleted node_modules a few times to ensure i was having the right result, but looks to be working fine only changing the import |
Hi! Thanks for your investigation @brlocky @tiagosiebler . Changing the import solves indeed the issue for RestClientV5 but not WebsocketClient .. Here is RestClientV5 working (same as you) : > working fine Here is the exact same but with
I don't know at all how to fix if you can help... |
for production, you have to do npm i events |
Hi all, I started a new ReactJS project with Vite + SWC, but i'm having some weird issues, maybe someone can help me.
I have the exact same provider in an older react project and its working fine
So this is the error message on the console
Currently testing with provider but already tested in the component, same result
The text was updated successfully, but these errors were encountered: