简体   繁体   English

打字稿找不到模块量角器

[英]Typescript cannot find module Protractor

I am integrating e2e testing in my project. 我正在将e2e测试集成到我的项目中。 The project uses Typescript (2.6.1). 该项目使用Typescript(2.6.1)。

I have just installed Protractor (5.2.0) but no matter what I do Typescript cannot import anything from the Protractor module. 我刚刚安装了量角器(5.2.0),但是无论我做什么,Typescript都无法从量角器模块中导入任何内容。

My tsconfig looks like this: 我的tsconfig看起来像这样:

{
    "compilerOptions": {
        "target": "es5",
        "module": "amd"
    },
    "exclude": [
        "./spec",
        "./node_modules",
        "./bower_components"
    ]
}

My very simple try out test looks like this: 我非常简单的试用测试如下所示:

import { browser } from "protractor";

describe("test should run", () => {
    it("should navigate to the page", () => {

    });
});

I get the following error: TypeScript error: usermanagement/ts/controllers/RolesController.e2e.ts(1,25): error TS2307: Cannot find module 'protractor'. 我收到以下错误: TypeScript error: usermanagement/ts/controllers/RolesController.e2e.ts(1,25): error TS2307: Cannot find module 'protractor'.

Looking at the Protractor installation in my node_modules folder I do find a reference to a typings file and the actual typings themselves. 在我的node_modules文件夹中node_modules Protractor安装后,我确实找到了对node_modules文件和实际键入本身的引用。 However Typescript simply does not 'see' them. 但是Typescript根本不会“看到”它们。 Interestingly Typescript has no problem finding typings in the node_modules/@types folder. 有趣的是,Typescript在node_modules/@types文件夹中查找node_modules/@types没有问题。

Anyone know what I am doing wrong? 有人知道我在做什么错吗?

In your tsconfig add: 在您的tsconfig中添加:

"module": "commonjs" 

More 更多

This is the recommended config I mention here as well https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html 这是我在这里提到的推荐配置https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM