-
Notifications
You must be signed in to change notification settings - Fork 32
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-js from ES module does not work #37
Comments
Many thanks for the I used following workaround to load OSC:
const websocketPlugin = new self.OSC.WebsocketClientPlugin();
const osc = new self.OSC( { plugin: websocketPlugin });
osc.open({ host, port }); However, it would be nice if |
Thank you @olange! I updated the project dependencies (#39), including a new version of rollup which contains the fixed umd global variable detection (rollup/rollup#2594):
Will merge this soon after a few more tests and new features. |
Hi @adzialocha, many thanks for the update of the dependencies! I confirm that your update of Rollup allows to import OSC-js with ES6 module import syntax. I checked out the I removed the
|
Great! Thank you @olange for the report. I merged the changes, bumped the version and published it (https://github.com/adzialocha/osc-js/releases/tag/v2.0.3). |
Many thanks!! 👍😺 |
Note: with this fix, the OSC-js library lives in global scope after that I guess an additional ES module build should be produced next to the UMD/AMD build, to allow to load the OSC library in module scope instead of global scope. I am not familiar with Rollup, but I stumbled upon an example in the que-etc/resize-observer-polyfill library; in its rollup.config.js, it defines two build steps:
Then in package.json, it uses the
Finally I guess your module would need to have a named and default export, which Rollup would use as different entry points to the two builds. Sorry for these many speculative observations, as of today I never produced such alternative builds. I am using ES modules / import syntax first hand. I will try to use Rollup on my own library, to produce these alternative builds. May be I will then contribute a more constructive PR to your library 🤓 |
I would like to import OSC from a Web Component in a web app (that, in browser), using the ES module import syntax:
You would assume I have added the module as dependency of my
package.json
and did runnpm install
to retrieve theosc-js
package from the NPM registry:The build of OSC-js 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 process; naively, I would think it is a matter of updating the UMD wrapper that the bundler is using to its latest version – as the above mentioned UMD issue was fixed and merged on 13.10.2017.
The text was updated successfully, but these errors were encountered: