Type file missing when using vue-tsc
Describe the bug
The bug happened when I use webpack with module federation 2.0 to build my Vue App. When I run pnpm start in container folder, A type declaration file is missing from @mf-types.zip in the dist directory.
Then I read the source code, I find in packages/dts-plugin/src/core/lib/typeScriptCompiler.ts, function createHost rewrites the writeFile of typescript,but this looks useless under vue-tsc. Whether it is a component or a function, the following code doesn't seem to execute, and the target .d.ts file cannot be generated. By the way, in vue-tsc, sourceFile.fileName seems to be App.vue.ts, not App.vue, so the following code may be wrong.
// packages/dts-plugin/src/core/lib/typeScriptCompiler.ts
for (const sourceFile of sourceFiles || []) {
const sourceEntry = mapExposeToEntry[normalize(sourceFile.fileName)];
if (sourceEntry) {
const mfeTypeEntry = join(
mfTypePath,
`${sourceEntry}${DEFINITION_FILE_EXTENSION}`,
);
const mfeTypeEntryDirectory = dirname(mfeTypeEntry);
const relativePathToOutput = relative(mfeTypeEntryDirectory, filepath)
.replace(DEFINITION_FILE_EXTENSION, '')
.replace(STARTS_WITH_SLASH, '')
.split(sep) // Windows platform-specific file system path fix
.join('/');
originalWriteFile(
mfeTypeEntry,
`export * from './${relativePathToOutput}';\nexport { default } from './${relativePathToOutput}';`,
writeOrderByteMark,
);
}
Reproduction
https://github.com/HUST-SE-LY/mf-vue3-demo
Used Package Manager
pnpm
System Info
System:
OS: macOS 14.4.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 2.64 GB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.20.1 - ~/.nvm/versions/node/v18.20.1/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.5.0 - ~/.nvm/versions/node/v18.20.1/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
Browsers:
Chrome: 125.0.6422.142
Safari: 17.4.1
Validations
- [X] Read the docs.
- [X] Read the common issues list.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Module federation issue and not a framework-specific issue.
- [X] The provided reproduction is a minimal reproducible example of the bug.
@2heal1 do you have any idea here why it is not detected?
Hello,
i have a similar issue by using module federation quick start rsbuild example converted to vue3
let me check this
as mentioned in issue 2685 HUST-SE-LY's comment , it works with latest vue-tsc 1.x (1.8.27). Regarding rsbuild, it doesn't provide vue-tsc by default for vue3 typescript projects as it uses tsc directly to build. So, it would be nice to get the types generated with tsc directly.
I find [email protected] will not use writeFile anymore , so this is the reason why our logic not work .
And the vue-tsc@<1.7.0 also has some questions , as @WeetA34 say , i will try tsc instead to see if it can work
I check again and find it can not use tsc to compile .vue file .
I will fix the issue by re-implement the ts compile.
upgrade @module-federation/[email protected] , the issue should be fixed
I'll test that soon. thank you
It works fine with vue-tsc 2.0.28 and @module-federation/[email protected] and the following dts config:
dts: {
generateTypes: {
compilerInstance: 'vue-tsc',
},
},
Unable to compile federated types, Error: compile TS failed, the original command is 'npx vue-tsc --project node_modules/.federation/tsconfig.a7b0ede872d63bdbfb5ee8bcadd8473a.json'
Stale issue message