Description
I am using roslibjs with a project that uses Vite as the build system and am running into an issue when running the project in development.
- Library Version: 1.3.0
- ROS Version: Galactic
- Platform / OS: Ubuntu 20.04
- Vite Version: 2.9.9
Steps To Reproduce
Minimum reproducible project here: https://github.com/kavidey/vite-sample-roslib
Run npm run dev
to get the error, or npm run build
then npm run preview
to see the project working properly.
Expected Behavior
In both dev and preview mode, importing roslibjs should work without any errors.
Actual Behavior
When running the code in dev mode, I get the error: ReferenceError: Can't find variable: Buffer
.
That error traces back to core/Ros.js
requiring ws
. I think that the ws
shim may not be working correctly when vite is running in dev mode and roslibjs thinks that its running in node so it tries to require ws
, though I'm not sure.