Skip to content
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

Importing OSC from ES module does not work– update UMD wrapper to latest version #137

Closed
olange opened this issue Feb 27, 2019 · 3 comments

Comments

@olange
Copy link

olange commented Feb 27, 2019

I would like to import OSC from a Web Component in a web app (that, in browser), using the ES module import syntax:

import { OSC } from "osc";

const osc = new OSC();
osc.open({ host, port });

You would assume I have added the module as dependency of my package.json and did run npm install to retrieve the osc-js package from the NPM registry:

  …
  "dependencies": {
    "osc-js": "^2.0.2",
   …
  },

The build of OSC version 2.0.2 currently does not support module imports. Its build uses a version
of the UMD wrapper, which contains a common bug, the incorrect detection of browser global in strict mode implied by module imports (see umdjs/umd#125).

I am unfamiliar with the build you're using, but it seems to me, it would a matter of updating the UMD wrapper you're using to the latest version – as the above mentioned UMD issue was fixed and merged on 13.10.2017.

@olange
Copy link
Author

olange commented Feb 27, 2019

By the way: may thanks for the osc-js library. We're successfully using it in our @petitatelier/three-web-components/three-camera web component.

We used following workaround to load OSC:

  1. Add a <script src="../node_modules/osc-js/lib/osc.min.js"></script> element in the HTML page that bootstraps the web app (demo);
  2. Reference OSC in global scope with the self keyword:
const websocketPlugin = new self.OSC.WebsocketClientPlugin();
const osc = new self.OSC( { plugin: websocketPlugin });
osc.open({ host, port });

However, it would be nice if it could simply be imported by the web component itself, so users won't need to worry about adding (add forgetting to add!) one other <script src="…"> to every page using the web component.

@colinbdclark
Copy link
Owner

Hi @olange, I think maybe the issue you filed is for a different library? Unfortunately, someone else decided to create a different library with the confusingly similar name osc-js, which, based on the same code you've provided, sounds like the library you're using.

@olange
Copy link
Author

olange commented Feb 28, 2019

Hi @colinbdclark, you're right, I apologize. I indeed got confused and the issue I reported was intended for @adzialocha/osc-js library. I will close this issue and report there.

@olange olange closed this as completed Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@colinbdclark @olange and others