Typescript 找不到模組 Protractor
我正在將端到端測試整合到我的專案中。該專案使用 Typescript(2.6.1)。
我剛剛安裝了 Protractor (5.2.0),但無論我做什麼,Typescript 都無法從 Protractor 模組匯入任何東西。
我的 tsconfig 看起來是這樣的:
{
"compilerOptions": {
"target": "es5",
"module": "amd"
},
"exclude": [
"./spec",
"./node_modules",
"./bower_components"
]
}
我非常簡單的嘗試測試看起來像這樣:
import { browser } from "protractor";
describe("test should run", () => {
it("should navigate to the page", () => {
});
});
我得到以下錯誤:TypeScript 錯誤: usermanagement/ts/controllers/RolesController.e2e.ts(1,25): 錯誤 TS2307: 找不到模組 'protractor'。
在查看我 node_modules 資料夾中的 Protractor 安裝時,我確實找到了對 typings 文件的參考以及實際的 typings 文件。然而 Typescript 根本無法『看到』它們。有趣的是,Typescript 在 node_modules/@types 資料夾中找到 typings 則沒有問題。
有人知道我做錯了什麼嗎?
答案#1
在你的 tsconfig 中添加:
"module": "commonjs"
更多
這就是我在這裡也提到的推薦配置 https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
