Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

TS2440: Import declaration conflicts with local declaration of 'PluginConfig'. #5348

Closed
SACHINBN opened this issue Nov 6, 2019 · 27 comments
Closed

Comments

@SACHINBN
Copy link

SACHINBN commented Nov 6, 2019

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

@josh-s-g
Copy link

josh-s-g commented Nov 6, 2019

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

@DanikRaikhlin
Copy link

Same issue here with Protractor 5.4.2 and Angular 8

@mattcasey
Copy link

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! :)

@akwiatek
Copy link

akwiatek commented Nov 6, 2019

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):
89fbf75
37bef24
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

@sandersn
Copy link
Contributor

sandersn commented Nov 6, 2019

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.

@SACHINBN
Copy link
Author

SACHINBN commented Nov 7, 2019

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

@mattcasey
Copy link

mattcasey commented Nov 7, 2019

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

@woppa684
Copy link

woppa684 commented Nov 13, 2019

@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?

@ayoubde
Copy link

ayoubde commented Nov 13, 2019

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", ... }

@anicarrr
Copy link

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

@benbreaker0412
Copy link

benbreaker0412 commented Nov 24, 2019

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!

@VenkatSaripilli
Copy link

Same issue and when I downgraded to 3.6.4 it worked.

@SamuelMarks
Copy link

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…

@mattcasey
Copy link

mattcasey commented Nov 26, 2019

@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.

@tomyam1
Copy link

tomyam1 commented Dec 6, 2019

An alternative solution we used is to create a modified build of protractor with the fixes in #5326

We than temporarily use it instead of protractor

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

@bluebaroncanada
Copy link

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

@lucky1895
Copy link

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?

@JonWallsten
Copy link

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

@anicarrr
Copy link

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

filipesilva added a commit to andrius-pra/angular that referenced this issue Jan 8, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of angular@2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.
devversion pushed a commit to andrius-pra/angular that referenced this issue Jan 11, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of angular@2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.
andrius-pra pushed a commit to andrius-pra/angular that referenced this issue Jan 14, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of angular@2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.
IgorMinar pushed a commit to andrius-pra/angular that referenced this issue Jan 15, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of angular@2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.
atscott pushed a commit to angular/angular that referenced this issue Jan 15, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of 2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.

PR Close #33717
atscott pushed a commit to angular/angular that referenced this issue Jan 15, 2020
With TS 3.7, these examples were running into the error below (e.g. on https://circleci.com/gh/angular/angular/574906#tests/containers/0):

```
============== AIO example output for: /home/circleci/ng/aio/content/examples/observables/
running: yarn tsc --project ./
$ /home/circleci/ng/aio/content/examples/observables/node_modules/.bin/tsc --project ./
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'PluginConfig'.
../../../tools/examples/shared/node_modules/protractor/built/index.d.ts(5,24): error TS2440: Import declaration conflicts with local declaration of 'ProtractorPlugin'.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
completed: yarn tsc --project ./
```

This happened because of angular/protractor#5348.

It's unclear why this typings problem does not affect `ng e2e` runs, and only affects `tsc` runs.

For now it seems sensible to alter the tests to compile only the app and not the e2e, since the intent of 2cc954d was never to verify the correctness of the e2e in the first place.

We still need a release of protractor that supports TS 3.7 though, but at least it doesn't seem to block our update proper.

PR Close #33717
@IgorMinar
Copy link

This was fixed in #5326. We are working on getting a patch release out.

@IgorMinar
Copy link

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

@ameyasworld
Copy link

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

@Nishit-Zinzuvadiya
Copy link

Nishit-Zinzuvadiya commented Jan 28, 2020

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

@Serhioromano
Copy link

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');

@antman2
Copy link

antman2 commented Aug 25, 2020

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';

@archywillhe
Copy link

still got this in 4.0.2.. hmmm

@nikita-fuchs
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests