2016-07-07 250 views
5

我使用webpack創建了Typescript項目,跟在this tutorial之後。 由於我有很多的模塊,我加index.d.ts我的src /組件,其中我出口我的所有模塊的文件夾:Typescript,index.d.ts和webpack:找不到模塊錯誤

export {Module1} from "./Module1"; 
export {Module2} from "./Module2"; 
export {Module3} from "./Module3"; 

我加index.d.ts到tsconfig.json文件:

"files": [ 
    "./src/components/index.d.ts" 
] 

然後,在index.tsx,這是在src文件夾中,我輸入:

import * as MyModule from "./components/"; 

代碼提示工作得很好,所以我想所有的路徑都OK。 然而,當我運行的WebPack,我得到這個錯誤:

模塊未找到:錯誤:無法解析目錄」 ./components'

據我瞭解,的WebPack沒有找到這個index.d。 ts文件。我嘗試將d.ts添加到webpack.config.js擴展名,例如described here,但後來我收到了一條不同的錯誤消息。我錯過了什麼嗎?

回答

2

想出了一個解決方案,將index.ts用於所有導出,而不是index.d.ts。

相關問題