2017-06-04 18 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

相关问题