-
Notifications
You must be signed in to change notification settings - Fork 387
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 roslibjs and Vite #548
Comments
I have really no clue. I also have to say this is a bit out of the support scope. I have to say I have never experienced any issue with webpack-dev-server. When you are able to provide a solution that requires to be implemented in the library, I am open to that. But I am not able to help you finding that solution. |
Just replace import 'roslib/build/roslib' with import 'roslib/build/roslib' |
@desstiony you suggest to replace it with the same.... |
Sorry, I made a typo. you should replace "import * as ROSLIB from 'roslib'" with 'roslib/build/roslib' in main.js file. |
So you mean replace |
Just |
I am not using Vite. It wasn't clear to me. So I thought it might not be clear to other people. |
I have tried it in the codespace of this repository hope it can help you. @kavidey |
Thank you @desstiony. This is a great fix for now! Because we're importing the fully compiled browser version, it creates a global I added a shim file to simplify the import syntax, so now it looks like I think if possible it would be great to try and find a solution that doesn't require using the precompiled version of roslib, but this works great for now! |
The issue with the import shim failing is likely due to vitejs/vite#7576, which is waiting on PR vitejs/vite#8709. A workaround is possible by using Vite's Lines 8 to 14 in 7aac4c5
In {
// ...
resolve: {
alias: {
'./src/RosLibNode.js': './src/RosLib.js',
canvas: './canvas',
ws: '../util/shim/WebSocket',
'@xmldom/xmldom': '../util/shim/@xmldom/xmldom',
'../util/decompressPng': '../util/shim/decompressPng',
}
}
} Note the above could have undesireable side effects if you so happen to also import those paths. Alternatively, why not import the shims directly then use the below trick to either import the NodeJS dependencies or browser dependencies? roslibjs/src/util/shim/WebSocket.js Line 1 in 7aac4c5
|
Bumps [karma](https://github.com/karma-runner/karma) from 6.3.17 to 6.4.0. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](karma-runner/karma@v6.3.17...v6.4.0) --- updated-dependencies: - dependency-name: karma dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Is there any difference? |
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.
Steps To Reproduce
Minimum reproducible project here: https://github.com/kavidey/vite-sample-roslib
Run
npm run dev
to get the error, ornpm run build
thennpm 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
requiringws
. I think that thews
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 requirews
, though I'm not sure.The text was updated successfully, but these errors were encountered: