Hi, I am trying to create a custom widget using nats.js library to connect with nats server.
I am follwing the documentation - https://github.com/nats-io/nats.js/blob/main/runtimes.md#running-in-the-browser
I want to import websocket library - @nats-io/nats-core into the code using url - https://cdn.jsdelivr.net/npm/@nats-io/nats-core@3.0.2/lib/nats.min.js) and url - (https://cdn.jsdelivr.net/npm/@nats-io/nats-core@3.0.2/+esm)
I am getting error -
Failed to load NATS.js: {}
could you please help me with what steps to take in order to load external library?
@OlgaStroilova Using above solution I am getting the error as show in the screenshot.
is there a specific build of the library required for custom widget?
I did as you suggested @tokotu but I am still getting above error, and Additionally I checked browser console, looks like nats.js url is not valid.
Is there a specific build of url needed to load into custom widget?
@p.bhagwan.gaikwad it looks like the error is saying the URL is not valid. Looks like the URL in your second post is indeed not valid but the original one is loading:
@OlgaStroilova it’s the same issue, the url is loading but its giving error as well.
In browser, it’s not allowing me to use library with “export” or “require”
I am trying to build and UMD version of the nats.js library side by side if there is no working URL.
That JS package does not appear to be directly usable in the browser. You need to run the code through a JS bunder to transpile it to a syntax that the browser can use.