打字稿找不到模块量角器

Typescript cannot find module 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 error: usermanagement/ts/controllers/RolesController.e2e.ts(1,25): error TS2307: Cannot find module 'protractor'.

查看我的 node_modules 文件夹中的量角器安装,我确实找到了对打字文件和实际打字本身的引用。但是 Typescript 根本不 'see' 它们。有趣的是,Typescript 在 node_modules/@types 文件夹中查找类型没有问题。

有人知道我做错了什么吗?

在你的 tsconfig 添加:

"module": "commonjs" 

更多

这也是我在这里提到的推荐配置https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html