core icon indicating copy to clipboard operation
core copied to clipboard

Project with tsconfig.json with compilerOptions.paths and path aliases usage fails to compile federated types

Open HermanBilous opened this issue 1 year ago • 1 comments

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

HermanBilous avatar Jul 23 '24 12:07 HermanBilous