TypeScript should not use dependencies from an unrelated node_modules directory in a sibling directory #44362
Labels
Design Limitation
Constraints of the existing architecture prevent this from being fixed
Bug Report
🔎 Search Terms
wrong dependency unrelated node_modules sibling directory
Related: #30124 (Declarations are unexpectedly used from node_modules in parent directory) but this issue is about unexpectedly using node_modules from a sibling directory.
🕗 Version & Regression Information
⏯ Playground Link
Not reproducible on Playground because it requires a sibling folder containing a node_modules.
A fully self-contained minimal reproduction example is here on GitHub.
💻 Code
Originally I have posted this issue as a question on StackOverflow, but after several days of experimentation it feels more like a bug. Refer to the question for some more details if needed.
Consider a repository structure that contains two TypeScript projects:
common
: Some common that is used by the frontend as well.backend
: A code NodeJS server app.common/src/common.ts
The backend uses this common code like this:
backend/src/backend.ts
Further:
common/package.json
we have listeddayjs
as a dependency, and we have done annpm install
in common.backend/package.json
we forgot to listdayjs
as a dependency!🙁 Actual behavior
The backend compilation silently succeeds, ignoring the fact the dependency is missing. Apparently TypeScript simply picks the dependency from the sibling folder
common/node_modules
(deleting it makes the compilation fail).This is not in line with nodejs' behavior of resolving node_modules in parent directories only. Therefore, running the compilation result with nodejs crashes.
We have brought down our production server because of the false positive compilation.
🙂 Expected behavior
Compilation should fail, complaining about the missing dependency instead of picking it up from a sibling node_modules folder.
The text was updated successfully, but these errors were encountered: