Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency on @types/* can cause conflict in type definition resolution (Duplicate identifier for @types/node) #5

Closed
sompylasar opened this issue Jul 22, 2017 · 3 comments

Comments

@sompylasar
Copy link

https://github.com/KingHenne/custom-tslint-formatters/blob/f2376dfe122b0b03d96b55a7c70e6bffa26ea4ce/package.json#L36-L37

  "dependencies": {
    "@types/chalk": "^0.4.31",
    "@types/node": "^7.0.12",

When custom-tslint-formatters is used as a dependency of a module with npm-shrinkwrap.json that is required by a TypeScript module for Node which itself depends on @types/node, the @types/node get installed twice into node_modules (using npm@3).

When building the TypeScript module, having more than one @types/node of the same version causes a ton of errors about duplicate identifiers because TypeScript gets two definitions for the global Node symbols.
Here's a sample of these errors with both conflicting paths visible:

node_modules/@some-company/ts-build-tools/node_modules/@types/node/index.d.ts(4283,18): error TS2300: Duplicate identifier 'Protocol'.


118 type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex";
         ~~~~~~~~~~~~~~

node_modules/@types/node/index.d.ts(118,6): error TS2300: Duplicate identifier 'BufferEncoding'.


289     export class EventEmitter {
                     ~~~~~~~~~~~~

In this example, @some-company/ts-build-tools depends on custom-tslint-formatters and has npm-shrinkwrap.json, so npm ls looks like this:

├─┬ @some-company/ts-build-tools@1.0.0
...
│ ├─┬ custom-tslint-formatters@2.1.0
│ │ ├── @types/chalk@0.4.31
│ │ └── @types/node@7.0.38
...
├── @types/node@7.0.38
...

Related issue (with no solution as of now): microsoft/TypeScript#6496

The only workaround for now is to ensure only one declaration is installed, but this is impossible for packages that are dependencies.

As this package does not export any typings, these @types/ dependencies could be moved to devDependencies to avoid such behavior until the root issue is resolved within TypeScript compiler.

@unstubbable
Copy link
Owner

@sompylasar Thanks for reporting this issue. I just published v2.1.1 to fix it.

@sompylasar
Copy link
Author

@KingHenne Thanks!

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

No branches or pull requests

2 participants