Protractor: TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.

Created on 6 Nov 2019  ·  27Comments  ·  Source: angular/protractor

Hi Sir!

Bug report
I am getting following below error :

ERROR in [at-loader] ./node_modules/protractor/built/index.d.ts:5:10
TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
 
ERROR in [at-loader] ./node_modules/protractor/built/index.d.ts:5:24
TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.

  • Node Version: 10.5.0
  • Protractor Version: ~5.1.2
  • Angular Version: ^4.2.4
  • Browser(s): any
  • Operating System and Version Windows 10
  • Your protractor configuration file

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/*/.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};

  • Steps to reproduce the bug - npm run build fail

Feature Request
Please help me to resolve

Most helpful comment

May not be the best solution for everyone, but you should be able to fix this by adding the following in tsconfig.json:

"skipLibCheck": true

All 27 comments

As of today I'm getting the same issue (with Protractor 5.4.2 and Angular 8)

Same issue here with Protractor 5.4.2 and Angular 8

I ran into this today while upgrading our Typescript version. We're on AngularJS and it occurs for both Protractor 5.4.1 and 5.4.2. I do not get the error on Typescript 3.6.4 (3.6.x), but I do with Typescript 3.7.2 (3.7.x). I believe it's related to this breaking change: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#local-and-imported-type-declarations-now-conflict

Please fix; we need nullish coalescing! :)

Same problem here. My project is at Protractor 5.4.2 and we would like to migrate to TypeScript 3.7 .

It would be great to backport the fix (it surely works):
89fbf75d4103db2cd20fd0c1c4ca7efebc52c049
37bef24331c1012bfc2cc7d3fa259a00e69bd192
from master to 5.4.2

5.4.2 is the latest version available at npmjs.com .
6.0.0 contains breaking changes, so it is not good for my project.
( https://github.com/angular/protractor/blob/6.0.0/CHANGELOG.md )

CC: @sandersn @heathkit

Duplicate of #5325

Edit: I should clarify that I work on the Typescript team, not the Angular team. I talked to some team members who said they would try to publish a new 5.* version, but I believe the process is not simple.

Today I have downgraded the typescript version from 3.7.x to 3.6.x.,It is working fine . Thank you mattcasey

Thanks for clarifying @sandersn; that was going to be my next question. We don't rely on flow control and I tried updating to 6.0.0 but even that published package doesn't seem to have your fix yet. It'd be great if someone from the team could comment here: are we talking a few days, a few months, or more?

Edit: I'd offer to help but it seems like the hold-up is "just" in releasing a new version :)

Edit 2: Since the rest of our system has moved on to TS 3.7, the lesser of two evils for me was to override the types from protractor for now by linking to a custom .d.ts file in our tsconfig: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

@mattcasey Could you describe in a bit more detail how your current fix works? Just a copied index.d.ts file with the correct export paths and then use the path mapping to map protractor to the new file?

Update types/node dependency
npm install -g @types/node@8

Make sure that types/node is listed in both devDependencies and dependencies

"dependencies": { ... "@types/node": "^8.10.59", ... }, "devDependencies": { ... "@types/node": "^8.10.59", ... }

In case this happen with any module using typescript 3.7.2 you can use the "as" statement.

import { module as otherModuleName } from "./module"

Or you could export the module as default so you can use a different variable name

Today I have downgraded the typescript version from 3.7.x to 3.6.x.,It is working fine . Thank you mattcasey

It put "typescript": "~3.6" to file package.json then run "npm install" on terminal and it worked for me. Thanks!

Same issue and when I downgraded to 3.6.4 it worked.

Same issue here, I had to npm uninstall -g typescript so that the local version of tsc would take priority. I could've messed with PATH instead…

@woppa684 my fix is essentially to create my own types for Protractor and tell Typescript to ignore the one inside of node_modules. My protractor.d.ts (located in my project at test-e2e/protractor.d.ts) file looks like this:

// Note: This stub exists to override Protractor types which are incompatible with TS 3.7 as of 5.4.2 and 6.0.0
declare module 'protractor' {
    let browser: any;
    let element: any;
    let by: any;
    let ExpectedConditions: any;
    let until: any;
    let Key: any;
}

And then in tsconfig:

{
  ...
  "compilerOptions": {
    ...
    "paths": {
      "protractor": ["test-e2e/protractor.d.ts"]
    }
  }
}

This allows me to use Typescript 3.7 with the downside that protractor methods are no longer type-safe.

An alternative solution we used is to create a modified build of protractor with the fixes in https://github.com/angular/protractor/pull/5326/

We than temporarily use it instead of protractor

// package.json
"protractor": "tomyam1/protractor-ts3.7-fix"

I'm having this problem on devops with Angular. This just started happening. I went back and grabbed a package.json and package-lock.json from a time I know it worked.
I upgraded Angular. I tried several different typescript versions. It works on my local computer, but not on devops. It's only the vs build portion that's failing. The npm/ng stuff runs just fine.
Everything works completely on my system.
https://developercommunity.visualstudio.com/content/problem/855096/npm-ng-suddenly-not-working-conflict-pluginconfig.html

In case this happen with any module using typescript 3.7.2 you can use the "as" statement.

import { module as otherModuleName } from "./module"

Or you could export the module as default so you can use a different variable name

@anicarrr , Could you please provide an example for second answer u provided?

May not be the best solution for everyone, but you should be able to fix this by adding the following in tsconfig.json:

"skipLibCheck": true

In case this happen with any module using typescript 3.7.2 you can use the "as" statement.
import { module as otherModuleName } from "./module"
Or you could export the module as default so you can use a different variable name

@anicarrr , Could you please provide an example for second answer u provided?

I mean exporting like:

export default myModule

so then when you import it you can just use whatever name you want, like:

import whateverName from myModule

This was fixed in https://github.com/angular/protractor/pull/5326. We are working on getting a patch release out.

fyi: in the meantime using tsc compiler option "skipLibCheck": true should be a sufficient workaround for those affected by this issue.

Hi Sir!

Bug report
I am getting following below error :

ERROR in [at-loader] ./node_modules/protractor/built/index.d.ts:5:10
TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
 
ERROR in [at-loader] ./node_modules/protractor/built/index.d.ts:5:24
TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.

  • Node Version: 10.5.0
  • Protractor Version: ~5.1.2
  • Angular Version: ^4.2.4
  • Browser(s): any
  • Operating System and Version Windows 10
  • Your protractor configuration file

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/*/.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};

  • Steps to reproduce the bug - npm run build fail

Feature Request
Please help me to resolve

Hi SachinBN,

You need to change version of Typescript installed in project. Use below command in VS Code terminal to change version(without quotes).

"npm install -g [email protected]"

Once done, please check version of typescript in your project on VS Code, using below command

"tsc -v"

It should show 3.6.2. Please use same version in package.json file. Once version is changed to 3.6.2 execute "tsc" again, error should be gone.

Hope this helps.

Regards,

Ameya

I had this issue in my angular app and I am able to resolve it via removing the protractor import statement which is automatically added by the suggestions.

Like:

import { element } from 'protractor'
import { promise } from 'protractor'

Just remove them I will run as expected.
Mine worked, I hope your code work too.

Regards,
Nishit Zinzuvadiya

npx tsc -v
Version 3.8.3

Latest node and NPM.

My file

import * as mysql from "mysql2";

const config =
    process.env.NODE_ENV == "prod"
        ? {
            connectionLimit: 10,
            host: "*********.rds.amazonaws.com",
            user: "admin",
            database: "p_" + process.env.PROJECT_ID,
            password: "*********",
            prefix: `p_${process.env.PROJECT_ID}_`
        }
        : {
            connectionLimit: 10,
            host: "host.docker.internal",
            user: "root",
            database: "i**_project",
            password: "root",
            prefix: ""
        };


export const db = mysql.createPool(config);
export const prefix = config.prefix;

And I have same error

npm run start

> [email protected] start /workspaces/icod-prt
> npx tsc && node build/index.js

typings/modules/mysql2/index.d.ts:677:1 - error TS2440: Import declaration conflicts with local declaration of 'Connection'.

677 import Connection = require('~mysql2~mysql/lib/Connection');
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typings/modules/mysql2/index.d.ts:679:1 - error TS2440: Import declaration conflicts with local declaration of 'PoolConnection'.

679 import PoolConnection = require('~mysql2~mysql/lib/PoolConnection');
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typings/modules/mysql2/index.d.ts:680:1 - error TS2440: Import declaration conflicts with local declaration of 'Pool'.

680 import Pool = require('~mysql2~mysql/lib/Pool');
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typings/modules/mysql2/index.d.ts:682:1 - error TS2440: Import declaration conflicts with local declaration of 'PoolCluster'.

682 import PoolCluster = require('~mysql2~mysql/lib/PoolCluster');
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

typings/modules/mysql2/index.d.ts:684:1 - error TS2440: Import declaration conflicts with local declaration of 'Query'.

684 import Query = require('~mysql2~mysql/lib/protocol/sequences/Query');

Sometimes the TypeScript compiler just blames errors on someone else's smoking gun.

I got the OP's exact error message today while working on .spec.ts unit test files. Since I didn't need Protractor for unit tests I temporarily uninstalled it with npm uninstall protractor which then caused TypeScript to throw the real error:

ERROR in src/app/.../...spec.ts:12:30 - error TS2307: Cannot find module 'protractor'.
12 import { EventEmitter } from 'protractor';

The cause was Visual Studio Code had inexplicably created this automatic import statement instead of the normal one, import { EventEmitter } from '@angular/core';

still got this in 4.0.2.. hmmm

I had this issue in my angular app and I am able to resolve it via removing the protractor import statement which is automatically added by the suggestions.

Like:

import { element } from 'protractor'
import { promise } from 'protractor'

Just remove them I will run as expected.
Mine worked, I hope your code work too.

Regards,
Nishit Zinzuvadiya

For me it was VSCode's auto-import, that imported EventEmitter from Protractor instead of @angular/core. Fixing this fixed the issue for me.

Was this page helpful?
0 / 5 - 0 ratings