2017-10-07 67 views
0

我試圖根據https://github.com/angular/angular-cli/wiki/stories-third-party-lib@angular/cli上使用@types/stats。 但是,當我嘗試import * as STATS from 'stats.js'我得到了tslint錯誤。不能在@ angular/cli上使用Stats.js 1.4.4

[ts] Module '"stats.js"' resolves to a non-module entity and cannot be imported using this construct.

@類型/統計的index.d.ts

declare class Stats { 
    REVISION: number; 
    dom: HTMLDivElement; 
    /** 
    * @param value 0:fps, 1: ms, 2: mb, 3+: custom 
    */ 
    showPanel(value: number): void; 
    begin(): void; 
    end(): number; 
    update(): void; 
} 

declare module "stats.js" { 
    export = Stats; 
} 

src/Stats.js(Stats.js本身)

https://github.com/mrdoob/stats.js/blob/master/src/Stats.js

我想,爲什麼我得到錯誤的原因是@types/stats使用export =風格出口。

所以我應該使用import Stats = require('stats.js')但是@angular/cli默認使用"module": "es2015"

我該如何導入它?

+0

yes'import Stats = require('stats.js');'應該像類型def看起來像'declare module「stats.js」{export = Stats; }' – Kuncevic

回答

0

如果你確定你安裝的東西都正確。

npm install stats-js npm install @types/stats-js

你應該能夠將其導入這樣的: import * as STATS from 'stats';沒有」 .js文件。

+0

感謝您的回覆;) 我試圖使用不* stats-js *包但是* stats.js *包。他們是不同的。 –

相關問題