Skip to content

Type updates don't propagate in monorepo across package boundaries #30946

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

Closed
natew opened this issue Apr 13, 2019 · 16 comments
Closed

Type updates don't propagate in monorepo across package boundaries #30946

natew opened this issue Apr 13, 2019 · 16 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@natew
Copy link

natew commented Apr 13, 2019

Steps to Reproduce:

  1. In a yarn workspace monorepo, that uses references to build, update a package and it wont update the type definitions anywhere else besides that package.

I was looking for an open issue thinking this would be obvious, but don't see one. It's a huge annoyance working in a mono-repo, it means essentially youre hitting "restart TS server" many times a day.

Apologies if this is already opened.

@mjbvz mjbvz transferred this issue from microsoft/vscode Apr 15, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Apr 15, 2019

Can you share a small example project or describe your project structure in more detail

@mjbvz mjbvz removed their assignment Apr 15, 2019
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Apr 17, 2019
@natew
Copy link
Author

natew commented Apr 18, 2019

Yea, sorry for lack of detail here. I actually wonder if this isn't something weirdly specific to me, because I imagine a lot of people would have run into it.

I have a monorepo managed by yarn workspaces. All the packages share a parent tsconfig.base.json and use typescript, here's a typical config:

tsconfig.base.json:

{
  "compilerOptions": {
    "strict": true,
    "incremental": true,
    "declaration": true,
    "declarationMap": true,
    "module": "CommonJS",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2018",
    "noImplicitAny": false,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strictNullChecks": false,
    "strictFunctionTypes": true,
    "preserveConstEnums": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "jsx": "react",
    "allowJs": false,
    "sourceMap": true,
    "resolveJsonModule": true,
    "lib": ["es2017", "es2018", "dom"]
  },
  "typeAcquisition": {
    "enable": true
  }
}

tsconfig.json

{
  "extends": "../../tsconfig.base",
  "compilerOptions": {
    "composite": true,
    "outDir": "_",
    "rootDir": "src"
  },
  "include": ["src/**/*"],
  "references": [
    { "path": "../../packages/gloss" },
    { "path": "../../packages/use-store" },
    { "path": "../../packages/fast-compare" },
    { "path": "../../packages/ui" },
    { "path": "../models" },
    { "path": "../stores" },
    { "path": "../bridge" }
  ]
}

This is really more of a VSCode issue and I'm realizing I think I used the wrong tab to open this issue, but basically if I make a change to any package, the parents of it won't see the type update in VSCode. But if I go to Restart TS Server it will pick up.

Here's a short video of it.

@domoritz
Copy link

This is a big issue for me as well. I use project references and changing code in one project does not update the types for that first project used in another project. I think this is a TS and VSCode issue so it seems okay to file it here.

@domoritz
Copy link

Is this a duplicate of #26913?

@natew
Copy link
Author

natew commented Jun 5, 2019

Well it happens with or without references, any symlink module that updates won't get picked up until you restart the typescript server.

Given we use a monorepo and have pretty well-split-up packages, I actually hit cmd+shift+p > restart ts at least 50 times a day 😓

@natew
Copy link
Author

natew commented Jun 5, 2019

More information: I do have watch running inside typescript (Build > tsc: watch) from the root. It compiles everything fine, the types do change in the output directory. If I restart it picks up the changes properly. But it just doesn't look for updates until you do so.

@aleclarson
Copy link

Related: The extends property of tsconfig.json is resolved relative to the symlink instead of its real path.

@aleclarson
Copy link

Also related: The tsconfig.json of a linked dependency is not used when the main field of the dependency is a *.ts module.

@nilkanthjp
Copy link

I've been experiencing this as well for a couple months. Thanks to @natew for the tip on restarting TS server, I've just been restarting VSCode entirely 😂

@chrillewoodz
Copy link

Noticing this as well, you can also open the file which contain the updated types and VSC will pick them up. But that is annoying as hell as well.

@jpike88
Copy link

jpike88 commented Jul 29, 2020

This is a pain in the butt, having this issue as well

I just noticed this issue is over a year old.

Can we have some TS people at least weigh in on this? @sheetalkamat @RyanCavanaugh @sandersn @mjbvz

@steve-taylor
Copy link

Also related: The tsconfig.json of a linked dependency is not used when the main field of the dependency is a *.ts module.

Unfortunately, source-level dependencies don't really work in TypeScript. It's a shame, because I'd prefer that package consumers, not package authors, decide which environments (browsers, Node.js versions, or language features) are supported.

So with that in mind, you have to build your packages and point main to the built .js entrypoint (e.g. ./dist/index.js) and point types to the generated type definitions (e.g. ./dist/index.d.ts). Similarly, if you're also building your packages as ES modules, you should also point modules to the built module entrypoint (e.g. ./dist/index.mjs).

You end up with something like this in package.json:

"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",

@ghost
Copy link

ghost commented Aug 3, 2022

Any update on this? Seems to still be an issue

@DorianMazur
Copy link

This is still the issue

@natew
Copy link
Author

natew commented Jun 7, 2023

@steve-taylor that doesn't fix it, but strangely a few days ago for no reason at all this started working for me, I wonder if VSCode did something?

@RyanCavanaugh
Copy link
Member

I think this has been resolved by some changes in watch strategy. Please open a new issue with complete repro steps if you're seeing this. Thanks!

@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

10 participants