2017-06-18 244 views
0

我在Typescript中有一個項目,我想使用依賴項「localForage」:https://github.com/localForage/localForage如何在Typescript項目中使用「localForage」?

npm install @types/localforage --save

我用:

我用以下命令故宮安裝了

import * as localForage from "localforage"; 

,我得到的錯誤:

error TS1148: Cannot compile modules unless the '--module' flag is provided I was looking for solutions and I found TypeScript 0.9.* VisualStudio TS5037: Cannot compile external modules unless the '--module' flag is provided.

這是不相關的我因爲我用Webstorm 10.0.5

+0

你需要實際安裝的模塊中遇到的問題 - 'NPM我localforage' - @types包只是打字稿定義 – Seiyria

+0

我試過了。沒有幫助 – CrazySynthax

+0

我開了一個新問題。這個可以刪除。 – CrazySynthax

回答

2

Settings | Languages & Frameworks | TypeScript - Set options manuallyUse tsconfig.json中選擇了什麼選項?在前一種情況下,請確保將--module commonjs指定爲命令行選項的值。否則,請將"module": "commonjs"添加到您的tsconfig.json中。

請注意,您使用的是很舊webStorm版本,它的打字稿整合是沒有及時更新,您可以使用最新版本的打字稿

+0

對不起,但這不是正確的方法。你發佈了這個問題,得到了答案;然後將問題改爲另一個。現在,接受的答案與這個問題無關。你希望我刪除我的答案,併發佈一個新的呢?然後,您將再次更改您的問題等。一旦問題得到解答,如果您有任何問題,請發佈新問題 – lena

+0

您是對的。我將它改回到您回答的原始帖子。 – CrazySynthax

相關問題