-
Notifications
You must be signed in to change notification settings - Fork 87
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
Duplicate definition of types when multiple entrypoints #321
Comments
Currently this is hard to implement. The rollup process is powered by |
I see, I don't have any suggestions on how to fix this without a rewrite, unless ms-api-extractor can be configured to fix it. |
I just ran in to a very similar problem with symbols being duplicated between entrypoints. With multiple entrypoints and rolled up types, I would still expect a common .d.ts file extracted that all entrypoint .d.ts files can import from so that the |
I also ran into the same problem. Any work arounds? |
Maybe you can try to build common types lib, and other packages import shared types from this lib. |
I have managed to make this work with tsup. Have tsup produce dts files then move them over to dist files produced by vite. (For my case, I want separate .js and .d.ts files for each component in dist folder.) tsup --dts-only && mv types/* dist && rm -rf types tsup.config.ts : import { defineConfig } from 'tsup';
import { globSync } from 'glob';
import { resolve } from 'path';
const components = globSync('src/components/*/index.ts').map(path =>
resolve(__dirname, path),
);
const entry = components.reduce((acc, path) => {
const componentName = path.split('/').at(-2);
acc[componentName!] = path;
return acc;
}, {});
export default defineConfig({
dts: true,
sourcemap: true,
outDir: 'types',
format: ['esm'],
entry,
loader: {
'.scss': 'text',
},
}); |
Describe the bug
I have a project where I have two entrypoints, one is for the base functionality, one is for react specific functionality.
vite-plugin-dts
handles two entrypoints quite well, and creates seperated.ts
files for bothindex.js
andreact.js
.The problem is they use common functionality, Vite detects this and extract this functionality into a seperate file, so both entrypoints can import from it.
vite-plugin-dts
takes a different approach to solve this problem; it inserts the typings in both .d.ts files instead of creating this "CommonCode" file. This leads to two definitions of several of the types, and leads to some interesting type mismatch bugs.I only discovered this bug because I had a class in the common code, which defines
private readonly some_value
.Reproduction
https://github.com/Kegulf/vitejs-vite-jbxngt
Steps to reproduce
In package.json
vite.config.ts
System Info
Validations
The text was updated successfully, but these errors were encountered: