module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.52k stars 235 forks source link

[Bug]: tsserver cannot resolve @modern-js/runtime/mf when tsconfig moduleResolution = Bundler #3106

Open yf-yang opened 2 weeks ago

yf-yang commented 2 weeks ago

Describe the bug

When using modern.js with module federation and host's tsconfig sets moduleResolution as bunder, @modern-js/runtime/mf could not be correctly resolved by typescript server.

To reproduce: Open the reproduction in an editor and install packages Open file modernjs-ssr/host/src/components/dynamic-remote.tsx

Diff of the reproduction: https://github.com/module-federation/module-federation-examples/commit/81b3fdefed6928d5449b0972fb52c5182c50b7f0

File modernjs-ssr/tsconfig.json has overiden the moduleResolution as Bundler, then node_modules/@module-federation/modern-js/types.d.ts is no longer loaded by the tsserver, so package @modern-js/runtime/mf is only resolved to @modern-js/runtime/* (provided by node_modules/@modern-js/app-tools/lib/types.d.ts) and all the symbols provided by @module-federation/modern-js cannot be resolved.

Is there any workaround for this?

Reproduction

https://github.com/yf-yang/module-federation-examples/tree/modernjs-bug

Used Package Manager

pnpm

System Info

Not related

Validations

yf-yang commented 2 weeks ago

Workaround: instead of import from @modern-js/runtime/mf, import from @module-federation/modern-js/runtime Documents of module federation suggests @modern-js/runtime/mf, but I don't know why you would prefer such a package alias instead of simply @module-federation/modern-js/runtime. Not sure if the issue is easy to fix.