Skip to content

Commit

Permalink
use advice to add: esModuleInterop": true from peers/peerjs#483
Browse files Browse the repository at this point in the history
add attempts of import
  • Loading branch information
andrewm committed Jul 10, 2019
1 parent 5db26f8 commit e630355
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,104 @@ Uncaught ReferenceError: parcelRequire is not defined
```


Attempts of various import methods:

#1
```
import * as Peer from 'peerjs';
```
compile error:
```
ERROR in src/app/app.component.ts:14:16 - error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
14 let peer = new Peer();
~~~~~~~~~~
src/app/app.component.ts:3:1
3 import * as Peer from 'peerjs';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
```

#2

```
import { Peer } from 'peerjs'
```

compile error:

```
ERROR in src/app/app.component.ts:3:10 - error TS2305: Module '"../../node_modules/peerjs"' has no exported member 'Peer'.
3 import { Peer } from 'peerjs'
~~~~
```

#3

```
import Peer from 'peerjs'
```

compile error:

```
WARNING in ./node_modules/peerjs/dist/peerjs.min.js 1:292-296
Critical dependency: the request of a dependency is an expression
```

runtime:

```
Uncaught ReferenceError: parcelRequire is not defined
at push../node_modules/peerjs/dist/peerjs.min.js.parcelRequire.vHo1 (peerjs.min.js:1)
at Object../node_modules/peerjs/dist/peerjs.min.js (peerjs.min.js:1)
at __webpack_require__ (bootstrap:79)
at Module../src/app/app.component.ts (main.js:112)
at __webpack_require__ (bootstrap:79)
at Module../src/app/app.module.ts (app.component.ts:11)
at __webpack_require__ (bootstrap:79)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:79)
at Object.0 (main.ts:12)
```

#4

```
import Peer = require('peerjs');
```

compile error:

```
ERROR in src/app/app.component.ts(3,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead
```

runtime:

```
AppComponent_Host.ngfactory.js? [sm]:1 ERROR ReferenceError: Peer is not defined
at new AppComponent (app.component.ts:15)
at createClass (core.js:27863)
at createDirectiveInstance (core.js:27685)
at createViewNodes (core.js:38315)
at createRootView (core.js:38187)
at callWithDebugContext (core.js:39716)
at Object.debugCreateRootView [as createRootView] (core.js:38953)
at ComponentFactory_.create (core.js:26827)
at ComponentFactoryBoundToModule.create (core.js:22791)
at ApplicationRef.bootstrap (core.js:35343)
```





This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.0.

Expand Down
2 changes: 1 addition & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "../tsconfig",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

import { Component } from '@angular/core';
import * as Peer from 'peerjs';
import Peer = require('peerjs');



@Component({
selector: 'app-root',
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
Expand Down

0 comments on commit e630355

Please sign in to comment.