-
Notifications
You must be signed in to change notification settings - Fork 13.3k
npm-linked modules (duplicates or not) are not working. #31527
Description
Re:
- Typescript@next and npm linked node_modules #9566
- Conflict between several @types package #9771
- Typescript@next and npm linked node_modules #11916
- Duplicate type declarations with npm link #6496
Search Terms
"typescript ignore npm linked dependencies"
Suggestion
I'd like for TypeScript to automatically work with npm linked modules.
Use Cases
Prevents developers from wasting much time.
Examples
npm link anything, and it just works.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
More details
I'm on TS v3.4.5.
Even if a project's npm linked module has the exact same version of a dependency,
> npm ls react
my-project@2.1.1 /Users/trusktr/src/my-project
├─┬ my-lib@2.0.0 -> /Users/trusktr/src/my-lib
│ └── react@16.8.6
└── react@16.8.6
TypeScript complains. For example:
[0] ERROR in /Users/trusktr/src/my-lib/node_modules/@types/react/index.d.ts(2963,13):
[0] TS2717: Subsequent property declarations must have the same type. Property 'view' must be of type 'SVGProps<SVGViewElement>', but here has type 'SVGProps<
SVGViewElement>'.
This is quite problematic, especially when needing to link 3, 4, or 5 modules at once during development, and especially more so when those linked modules have other npm linked modules. This issue grinds the dev experience to a halt. This npm link workflow is commonplace in with plain JS projects using NPM.
I've tried all workarounds mentioned in the other four issues, but each workaround brings with it other problems, or just don't work.
One workaround is to remove the duplicate dependency in the npm linked module, and this causes everything to work fine in the project, but then typings don't work while working on the npm linked module. So to get back to developing the npm linked module, we need to reinstall the missing dependencies. Then when we switch back to the project we need to delete the dependencies in the linked package. Then when we switch back to the linked package... etc...
I believe that TypeScript should deeply embrace how npm link works, and provide a built in solution so that TypeScript users never run into this again.