Npm Required Vs Standalone Js? #1368
|
Looking at https://peerjs.com/client/getting-started, it makes me think it's meant to be node-based, yet I've been trying to get it to work through a browser. Something I came across was Npm (package dirs alone): npm's peerjs: Npm seems the way to go for the intellisense alone (derived from Looking at https://github.com/orgs/peers/discussions/1181, I'd guess that @jonasgloning might know what's up. I believe I may have gotten it to work with the npm packages, but I've gone through so many iterations of changes trying to figure out my problemS (plural, because it also relates to typescript pathing structure), I have to figure out that solution again. EDIT0: I had finally remembered the "hack" I did to force it to work... |
Replies: 1 comment
|
Both are real, supported ways to ship PeerJS - they are just two different build formats for two different workflows, and the errors you hit come from mixing them up. You can confirm all of this from the package's own build config ( The npm package = ES/CJS modules for a bundler. The standalone (window as any).peerjs = { Peer, util };
(window as any).Peer = Peer; // deprecatedSo this file is not an ES module and exports nothing - it only assigns to <script src="/lib/peerjs/peerjs.min.js"></script>
<script>
const peer = new Peer("pick-an-id");
</script>So which should you use?
One thing I would avoid: an import map pointed at that cdnjs Short version: nothing is strictly "required" - npm plus a bundler gives you importable modules and types, the standalone JS gives you a |
Both are real, supported ways to ship PeerJS - they are just two different build formats for two different workflows, and the errors you hit come from mixing them up. You can confirm all of this from the package's own build config (
package.jsontargetsplus thelib/global.ts/lib/exports.tssources on the repo).The npm package = ES/CJS modules for a bundler.
package.jsonpoints itsmodule/main/typesfields atdist/bundler.mjs,dist/bundler.cjsanddist/types.d.ts, all built fromlib/exports.ts. That file has the real named exports (Peer,PeerError, and type-only exports likeDataConnection,MediaConnection,PeerOptions, etc.). This is what makesimport { Peer, DataConnection } from …