You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to port the Jibo extension, which uses ROSLIB to the new extension framework (with the @blocks decorator). I discovered an issue I could not get around where importing roslib and trying to use it seems to break the ts-compiler and causes the extension to fail compiling.
I am unsure of the cause but importing and using roslib works perfectly in the old version of the extension famework (with defineBlocks). The issue may have something to do with how these different functions are defined.
Priority level: Low. At some point Jibo blocks will use firebase instead of roslib. It's just a weird bug.
Recreating the error
Go to a working example that uses the latest extension format (e.g. complex-example).
In the terminal, install roslib npm i roslib
At the top of the code, install roslib import ROSLIB from "roslib"
Somewhere in the code, make a call to ROSLIB. For example, place the following in init() let rosbridgeIP = "ws://localhost:9090"; let ros = new ROSLIB.Ros({ url: rosbridgeIP, }); console.log(ros);
In the terminal, compile and run the extension. npm run dev. Note: if you already had npm run dev running, stop it and restart it. Otherwise the error will not appear.
Expected behavior
The extension compiles successfully and everything works.
Actual behavior
During compile you get a ReferenceError about Websocket. Roslib uses websocket under the hood.
The overall compile fails.
Attempted fixes
Installied and imported Websocket. But since there's no direct Websocket call this didn't do anything.
Stopped using the newest style of the extension framework. Works, but a band-aid.
The text was updated successfully, but these errors were encountered:
The error is definitely due to the fact that, with the new extensions, we actually try to 'execute' the bundled up code (as the error suggests) because this forces all of the decorators to run allowing us to collect all the metadata about extensions and their blocks and do the necessary codegen. (but note the extension class is not actually instantiated, so the init function will not be ran).
It's certainly a little sketchy (as we are seeing here), but I think it's an improvement over how it worked with the 'old' extensions, which leveraged the typescript compiler to pull out these details -- unfortunately the typescript compiler is very undocumented, and I found it very difficult to work with, and didn't want to force anyone to work with it.
So, with all that preamble out of the way, what must be happening here is that ROSLIB references WebSocket within it's code that executes immediately so upon importing it, it immediately tries to interact with WebSocket (which is a little unexpected, since you'd expect it to likely reference it in a function definition instead, which would not trigger this error). Depending on where/how this is, there should be some easy workarounds, like by "stubbing" the WebSocket.
Is there a branch somewhere I could play around with this?
Thanks again for the clear and comprehensive report, @randi-c-dubs !
Description
I was trying to port the Jibo extension, which uses ROSLIB to the new extension framework (with the @blocks decorator). I discovered an issue I could not get around where importing roslib and trying to use it seems to break the ts-compiler and causes the extension to fail compiling.
I am unsure of the cause but importing and using roslib works perfectly in the old version of the extension famework (with defineBlocks). The issue may have something to do with how these different functions are defined.
Priority level: Low. At some point Jibo blocks will use firebase instead of roslib. It's just a weird bug.
Recreating the error
npm i roslib
import ROSLIB from "roslib"
let rosbridgeIP = "ws://localhost:9090"; let ros = new ROSLIB.Ros({ url: rosbridgeIP, }); console.log(ros);
npm run dev
.Note: if you already had npm run dev running, stop it and restart it. Otherwise the error will not appear.
Expected behavior
The extension compiles successfully and everything works.
Actual behavior
During compile you get a ReferenceError about Websocket. Roslib uses websocket under the hood.
The overall compile fails.
Attempted fixes
The text was updated successfully, but these errors were encountered: