Cannot import from typescript
Hello, despite looking at similar issues "apparently" resovled, typescript imports are broken:
- (Docs) import Peer from 'peerjs' --> has not default export
- import { Peer } from 'peerjs' --> has no exported member Peer
- import * as peerjs from 'peerjs' --> no TS error but at runntime, new Peer is not a function (its an object...)
Is there any quick fix to this, its really sad! :/
I am having the same issue! Thanks!
Should works
import Peer from 'peerjs';
console.log(new Peer())
My tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"types": [
"node"
],
},
"include": [
"src"
]
}
@caribeedu share your tsconfig please
This issue is preventing my team from using this library with Angular.
Is there any alternative way for us to import peerjs while allowing us to have types?
it's working just add the library and import it like this
import Peer from 'peerjs';
By adding esModuleInterop to the project's tsconfig.ts, we were able to successfully use peerjs and make a build with Angular 11:
{
// ...
"compilerOptions": {
// ...
"esModuleInterop": true, // <-- add this
}
}
By doing this, import Peer from 'peerjs'; works. We do get the warning: "Critical dependency: the request of a dependency is an expression" whenever we serve/build, but I haven't noticed anything odd yet. Also this warning isn't critical as mentioned here: peerjs FAQ.
Hopefully this solution works for you @adadgio
fixed in peerjs@beta