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

Unable to import Peer in Angular application #483

Closed
Pacific112 opened this issue Feb 7, 2019 · 13 comments
Closed

Unable to import Peer in Angular application #483

Pacific112 opened this issue Feb 7, 2019 · 13 comments

Comments

@Pacific112
Copy link

Issue #479 is still present. I am using version 0.3.20 of peerjs. 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
@tetriminoss
Copy link

Can confirm, tried peerjs on Ionic 4 (which i assume running Angular 6) with the same import method

@pReya
Copy link
Contributor

pReya commented Feb 13, 2019

Have the same problem using Webpack and CreateReactApp. Seems to be a new problem introduced in 0.3.20 or 0.3.19.

@kidandcat
Copy link
Member

I'm working on it, anyway any PR is welcome

@pReya
Copy link
Contributor

pReya commented Feb 13, 2019

Thanks @kidandcat ! I'd love to help, but I have no experience with TypeScript. Version 0.3.18 works fine, so no worries.

@mindfulmike
Copy link

Same here, using vue-cli

@kidandcat
Copy link
Member

Fixed in peerjs@0.3.22

@nhducseuit
Copy link

nhducseuit commented May 24, 2019

@kidandcat tried with 0.3.22 and 1.0.0 in Angular 7, this issue is still seen.

@kidandcat
Copy link
Member

How are you importing it

@nhducseuit
Copy link

nhducseuit commented May 25, 2019

How are you importing it

Few:
import * as Peer from 'peerjs' -> this one was complied successfully, however error was thrown same like in first comment
import { Peer } from 'peerjs' and import Peer from 'peerjs' -> these two caused compile error

I only install peerjs package, don't use @type/peerjs since index.d.ts is already available in peerjs package.

@nhducseuit
Copy link

@kidandcat I was able to resolve my issue by enabling following flag in tsconfig.json file

{
...
    "esModuleInterop": true,
...
}

@phongca22
Copy link

@nhducseuit what is the context did you use?

  1. import * as Peer from 'peerjs'
  2. import { Peer } from 'peerjs'
  3. import Peer from 'peerjs'

furozen pushed a commit to furozen/PeerJs-example that referenced this issue Jul 10, 2019
furozen pushed a commit to furozen/PeerJs-example that referenced this issue Jul 10, 2019
@lvargass
Copy link

I have this problem with ionic 4.

"@angular/common": "^7.2.2",
"@angular/core": "^7.2.2",
"@angular/forms": "^7.2.2",
"@angular/http": "^7.2.2",
"@angular/platform-browser": "^7.2.2",
"@angular/platform-browser-dynamic": "^7.2.2",
"@angular/router": "^7.2.2",
"@ionic-native/core": "^5.0.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.1.0",
"buffer": "^5.2.1",
"core-js": "^2.5.4",
"peerjs": "^1.0.2",

What I can do?

@ghost
Copy link

ghost commented Sep 18, 2019

@kidandcat I was able to resolve my issue by enabling following flag in tsconfig.json file

{
...
    "esModuleInterop": true,
...
}

Does this have any impact on anything else?
Could it break other things.
The documentation on typescript says something that is not really understandbble.
What does this esModuleInterop option actually do .Because we dont want to break other things.
https://www.typescriptlang.org/docs/handbook/compiler-options.html

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

8 participants