jszmq icon indicating copy to clipboard operation
jszmq copied to clipboard

Can't import jszmq into web browser

Open citkane opened this issue 3 years ago • 7 comments

I want to try out jszmq in the browser, but am stumped at the fundamentals of getting it imported.

Server Live Server from VS Code

Browser Firefox for Ubuntu 101.0.1

Installation npm install jszmq version 0.1.2 gets installed

HTML code

<head>
        ...
	<script type="module" src="./main.js"></script>
</head

main.js

import * as zmq from '../node_modules/jszmq/lib/src/index.js';
console.log(zmq);

expected outcome:

The module would import without any shimming or boilerplating. The zmq object would be logged to console.

actual outcome:

the below error is thrown to the console:

Uncaught ReferenceError: exports is not defined
    <anonymous> http://127.0.0.1:5500/node_modules/jszmq/lib/src/index.js:2
index.js:2:1

Can somebody please advise if I am missing a trick here?

citkane avatar Jul 03 '22 18:07 citkane

https://github.com/zeromq/czmq/issues/2158

sphaero avatar Nov 23 '22 11:11 sphaero

Does that help?

sphaero avatar Nov 23 '22 11:11 sphaero

Hi @sphaero, yes that helps, thank you very much.

I think it would make sense to include those steps in the README, otherwise it's pretty hard to figure this out.

michele-perrone avatar Apr 25 '23 06:04 michele-perrone

Can you add these instructions through a PR?

sphaero avatar Apr 26 '23 05:04 sphaero

Yes, will do.

michele-perrone avatar Apr 26 '23 06:04 michele-perrone

Hi, I follow the step to use browserify to convert the Javascript (with require("jszmq") to a bundled js. When I run the connect() method of Sub instance, I got an error at the line of the bundled js

new WebSocket(this.address, ['ZWS2.0']);

The error says: "WebSocket connection to 'ws://172.17.0.1:9802/' failed: "

However, the same URL can work with zeromq when I have a local js server running, in a separate project without using jszmq and browserify. Do I miss some obvious steps? Is there any information I can provide to help better illustrate the problem?

hyliu1989 avatar Apr 04 '24 20:04 hyliu1989

I think you'll need a better code snippet to explain the error. We can't tell what's going on from this.

sphaero avatar Apr 05 '24 08:04 sphaero