Description
"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.