-
Notifications
You must be signed in to change notification settings - Fork 84
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
Re-export types from monorepo internal dependencies #302
Comments
If the depended relationships are correct, TypeScript may always resolve the declarations map when you are using them. Like the following: // A.d.ts
import D from 'packageD'
interface A extends D {
// ...
} TypeScript will find the declaration files of |
@qmhc We need a fix for this. It's making life hard when using monorepos. For example, if there is at least one private package that is imported into another public package, the private import is not resolved for types currently. At least not consistently. It seems that if we have It would be great if we could tell to My proposal is to just decouple them the right way so that we make this plugin even more better. Keep it up! |
@ohkimur You can view this demo: https://stackblitz.com/edit/vitejs-vite-oaq33v?file=vite.config.ts&view=editor. If you think this is not match your case, you can edit it to reproduce you issue. |
@qmhc I've updated the demo with a situation as close to the one I have. Here is a link: https://stackblitz.com/edit/vitejs-vite-k5aekx If you go to import { Baz } from '@test/baz';
export interface Foo {
baz: Baz;
c: boolean;
}
export declare const foo: {
baz: number;
}; However, the It'll be better, in my opinion, to include the types of export interface Baz {
a: number;
b: string;
}
export declare const baz = 1;
export interface Foo {
baz: Baz;
c: boolean;
}
export declare const foo: {
baz: number;
}; NOTE: As I already mentioned previously, when using |
@ohkimur for me even adding import { Something } from './common_package'; but there is no my vite config export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, "src/index.ts"),
fileName: "index",
formats: ["es"],
},
target: "esnext",
outDir: "dist",
},
plugins: [
dts({
bundledPackages: ["common_package"],
rollupTypes: true,
staticImport: true,
beforeWriteFile: (filePath, content) => {
if (filePath.endsWith("index.d.ts")) {
return {
filePath: filePath.replace(/\.d\.ts$/, ".d.mts"),
content,
};
}
},
}),
wasm(),
],
}); added my dependency like this in package.json "dependencies": {
"viem": "^2.7.15",
"common_package": "*"
} even tried like this "dependencies": {
"viem": "^2.7.15",
"common_package": "file:../common"
} nothing seems to work |
@avp1598 Your setup is very similar to mine. I also use Here is how I setup the dts({
exclude: ["tests"],
outDir: "dist/types",
rollupTypes: true,
bundledPackages: ["@acme/*"],
}), |
@ohkimur I'm also running into similar problems. I have a monorepo setup with turborepo and pnpm and it has a couple of packages built with vite. I have a For some reason, having |
@pandeymangg Yeah, this is also the case for my monorepo. You can @qmhc Do you have any ideas on how to fix this? If you give at least some hints, I could make a PR to fix this one. |
@ohkimur Well, it's a difficult work. You need to analyze the relationship between packages, and manually find the modules and symbols in internal packages which are used in the public packages. After some research I found that it even need to use internal APIs of TypeScript. 😓 |
facing the same issue in monorepo, the dependencies may be a private module.it would be much better that |
I also encounter the issue. I have several packages in my monorepo, package A imports a shared type declaration from the internal package B. Package A will be built as a library with dts file distributed. In the distributed dts file, we still see the package B's path which will causes error if the developer installs this package. My workaround is to re-create an identical type in package A and only use it in package A. And leverage Vitest's type test to test if the re-created one is aligned with the original one in package B. |
Same problem with nx monorepo |
Maybe you can try the following workaround:
|
Description
I have a packageA in a monorepo and it depends on packageB and packageC, packageC depends on packageD.
When I run vite build on packageA using the dts plugin and
{ rollupTypes: true }
, I don't see the types from packageB, packageC, and packageD being exported from packageA.Suggested solution
Have a option that allows for types from dependencies to be included in the generated *.d.ts files
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: