2017-06-04 21 views
0

即時工作在項目上,我遇到問題。即時通訊使用Angular2,打字稿,webpack 2.2和即時通訊嘗試使用此表組件: pyrite table無法在TypeScript中導入TableComponentJS

當我嘗試在我的組件導入此組件時,問題開始。我用npm安裝它,並且工作。但是當我嘗試將其導入使用:import * as Table from "pyrite-table";

然後我嘗試使用Table.load但我得到一個錯誤:index.js:38 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

這行是這樣的:

export default module.exports = window.pyrite.Table = Table; 

所以我問題是,我如何導入這個組件在我使用typescript的項目中。

import Table from 'pyrite-table'; 

您是否嘗試過這一個:

回答

0

我在項目repo's自述以下祿看見?或者:

import { Table } from 'pyrite-table'; 
+0

是的,我試過了,但沒有工作(它說:沒有導出成員'表')。我在互聯網上讀到,你不能使用module.exports導入,但我不知道如何解決這個問題。 – Tibo

+0

所以試試這個:在'src'文件夾的某處創建'declarations.d.ts'文件,在'tsconfig.json'中添加這個文件的路徑,然後再試一次''從'pyrite-table'導入{Table};' 。 'declarations.d.ts'的內容應該是'declare module'pyrite-table''。欲瞭解更多信息,請參閱www.typescriptlang.org/docs/handbook/modules.html – embarq

+0

需要我在declarations.d.ts中寫些東西嗎?我如何在tsconfig中添加此文件的路徑?我在src/history中創建了一個空的declarations.d.ts,所以我加上了: 「declaration」:true,「declarationDir」:「history/declarations.d.ts」,' 我不知道它是否正確 – Tibo

相關問題