Project with tsconfig.json with compilerOptions.paths and path aliases usage fails to compile federated types
Describe the bug
When the project has a tsconfig.json with compilerOptions.paths, and the project uses them e.g. import { TEXT } from '@/module/text';, the types generation fails with errors:
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /project-path/node_modules/.federation/tsconfig.{hash}.json';
Error: ENOENT: no such file or directory, open '/project-path/dist/@mf-types.zip'
at Object.openSync (node:fs:581:18)
at Object.readFileSync (node:fs:457:35)
at _GenerateTypesPlugin.<anonymous> (/project-path/node_modules/.pnpm/@[email protected][email protected]/node_modules/@module-federation/dts-plugin/dist/index.js:2500:140)
at Generator.next (<anonymous>)
at fulfilled (/project-path/node_modules/.pnpm/@[email protected][email protected]/node_modules/@module-federation/dts-plugin/dist/index.js:54:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/project-path/dist/@mf-types.zip'
}
Running the original command produces following error:
src/module/Component.tsx:2:22 - error TS2307: Cannot find module '@/module/text' or its corresponding type declarations.
2 import { TEXT } from '@/module/text'
~~~~~~~~~~~~~~~
Found 1 error in src/module/Component.tsx:2
The issue seem to stem from compilerOptions.paths not being copied into generated tsconfig.json. The extends field in generated tsconfig file does not extend compilerOptions.paths.
This issue first appears in v0.2.7, the version before does not have this issue.
Reproduction
https://github.com/HermanBilous/mf-tsconfig-paths
Used Package Manager
pnpm
System Info
System:
OS: macOS 14.5
CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
Memory: 2.17 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.0 - /usr/local/Cellar/nvm/0.39.3/versions/node/v20.11.0/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 10.2.4 - /usr/local/Cellar/nvm/0.39.3/versions/node/v20.11.0/bin/npm
pnpm: 9.6.0 - ~/Library/pnpm/pnpm
bun: 1.1.6 - ~/.bun/bin/bun
Browsers:
Chrome: 126.0.6478.183
Edge: 126.0.2592.113
Safari: 17.5
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.
I have the same issue
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /my-project/node_modules/.federation/tsconfig.6a6a....db066.json'
when I use
{
"compilerOptions": {
...
"paths": {
"#/*": [
"./src/*"
]
},
...
}
}
@HermanBilous @intpp
I'm using the latest versions of module federation packages and it's working properly.
I though the problem was compilerOptions.paths and path aliases.
But I ran: npx tsc --project /home/<...>/node_modules/.federation/tsconfig.<blablabla>.json and discovered that my error was related to mui.
So I added @mui/system as dev dependency, and also import type {} from '@mui/system'; in my App.tsx file.
And now the federated types are been created successfully, even with compilerOptions.paths like @/*: [".src/*"].
I hope it helps somehow.
Hey @LeandroPereiraDaCruz, thanks for heads up. I tried running build and it worked, but only after I deleted the ./dist/ folder beforehand. Closing this.