Peerjs: Support using repo like an npm dependency (e.g. have tasks compile to dist/peer.js)

Created on 24 Jan 2019  ·  6Comments  ·  Source: peers/peerjs

Until the move to Typescript, the peerjs repo could have been used just like any other NPM depenency. Simply add dependency as "peerjs": "git+https://github.com/peers/peerjs.git" and it would get compiled into /node_modules/peerjs/dist/peer.js.

Thus a node application that is using the dependency could have easily imported it into an application and use peer.

However, with move to TS, we have a non-required postinstall tasks that break the usage in such scenario with an error (just try to clone use the current repo as a dependency via git and you'll know what I mean). Furthermore, even in we fork the current peerjs repo and remove postinstall, it still doesn't have an install or build tasks that would result in the creation of "dist/peer.js" file.

So my suggestion is to add those build tasks.
A Question - now with current repo configuration, how do I build the peerjs library into dist/peer.js?
Thanks.

Most helpful comment

@kidandcat
Apologies for reopening a closed issue, but I still can't use PeerJS as a module... To reproduce:

  • create a new react app yarn create react-app my-app
  • add peerjs dependency yarn add peerjs
  • edit src/App.js and add:
import Peer from "peerjs";
// ...
class App extends Component {
  componentDidMount() {
    const peer = new Peer('peer-id', {});
  }
  // ...
}
  • run the app yarn start

if you browse to http://localhost:3000 you will get:
TypeError: peerjs__WEBPACK_IMPORTED_MODULE_9___default.a is not a constructor

All 6 comments

@Caballerog

Selenium was removed from postinstall. Grunt tasks should work fine. Could you try with latest version? 0.3.19

Also to answer your question, the build is still done with grunt, it is in gruntfile.js. The main task is ts (typescript). After that are some minifying tasks.

To build you just need to use grunt, the best way is npx grunt.

@kidandcat
Apologies for reopening a closed issue, but I still can't use PeerJS as a module... To reproduce:

  • create a new react app yarn create react-app my-app
  • add peerjs dependency yarn add peerjs
  • edit src/App.js and add:
import Peer from "peerjs";
// ...
class App extends Component {
  componentDidMount() {
    const peer = new Peer('peer-id', {});
  }
  // ...
}
  • run the app yarn start

if you browse to http://localhost:3000 you will get:
TypeError: peerjs__WEBPACK_IMPORTED_MODULE_9___default.a is not a constructor

As @xavierfuentes said -> Issue is still present. To reproduce:

  • create new Angular app ng new app
  • npm install --save peerjs
  • edit app.component.ts file:
import * as Peer from 'peerjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';

  ngOnInit(): void {
    new Peer('123', {})

  }
}
  • npm start
    Result will be: ERROR TypeError: peerjs__WEBPACK_IMPORTED_MODULE_2__ is not a constructor

Sorry for the delay, [email protected] should fix the issue

This issue is still unresovled, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UnsungHero97 picture UnsungHero97  ·  5Comments

veezo2007pk picture veezo2007pk  ·  7Comments

bilo1967 picture bilo1967  ·  7Comments

RikdeVos picture RikdeVos  ·  6Comments

kahrkunne picture kahrkunne  ·  4Comments