@mf-types.zip not being generate since 0.2.7
Describe the bug
GenerateTypesPlugin is having trouble generating the zip file for @mf-types.
Replication is just bumping the plugins version to 0.3.3 of an rspack app from mf examples repo.
.
Reproduction
https://github.com/module-federation/module-federation-examples/tree/master/rspack_hmr/app2
Used Package Manager
pnpm
System Info
System:
OS: macOS 14.5
CPU: (10) arm64 Apple M2 Pro
Memory: 213.69 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 9.5.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
Browsers:
Chrome: 127.0.6533.89
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.
@2heal1 can you take a look?
i have same issue on webpack plugin
does the build crash? or just throw error?
does the build crash? or just throw error?
@ScriptedAlchemy Only warns. It doesn't crash. Types are being built, they appear inside the bundle, but they just don't get zipped apparently.
Types are being built, they appear inside the bundle, but they just don't get zipped apparently.
Hi guys! I bumped into the same exact issue, but in my case types are not generated at all. The bundle is built (static JS-chunks + manifest files), but neither /@mf-types folder nor @mf-types.zip is present inside /dist folder
The error i get when i run build script:
The /dist folder after build script execution
The @mf-types folder is being generated only when i manually try to run the ts-compile command from error message above, which is npx tsc --project <path-to-my-packege>/node_modules/.federation/tsconfig.8e832ac4f46027611fcdf3bf665e47de.json
I have "@module-federation/enhanced": "0.3.5" installed (using ModuleFederationPlugin webpack plugin).
Another problem is that dts options does not override the given defaults. When researching the problem, i was trying to give a types-zip-file another name according to the instructions https://module-federation.io/configure/dts#typesfolder :
dts: {
typesFolder: 'custom',
},
But when i run my build command again with specific typesFolder name, i still meet the same error message as it was:
ENOENT: no such file or directory, open '.../**@mf-types.zip'** saying that @mf-types.zip is missing but not the custom.zip as it is supposed to be.
Some updates to my notes here :)
So if we take a closer look to an error it firstly says that TS compile failed: Error: compile TS failed
and there is the log of the original command which is failed:
npx tsc --project <path-to-my-packege>/node_modules/.federation/tsconfig.8e832ac4f46027611fcdf3bf665e47de.json
So if i try to run this command manually i get i few TS erros while compiling. These errros come from @types/ws package:
Here is the exact place of code which TS doesnt like https://github.com/DefinitelyTyped/DefinitelyTyped/blame/master/types/ws/index.d.ts#L312
Soooo if i go to node_modules/@types/ws/index.d.ts and manually remove generics from the type (i know it is a dirty hack but wanted to check if it will work) it fixes TS compilatiion. And when i re-run my build command again all the types and zip-file itself generate successfully π₯³
So the problem of not building @mf-types.zip is the TS error inside @types/ws package:
node_modules/@types/ws/index.d.ts:312:18 - error TS2315: Type 'Server' is not generic.
312 server?: HTTPServer<V> | HTTPSServer<V> | undefined;
This is where this line of code is declared https://github.com/DefinitelyTyped/DefinitelyTyped/blame/master/types/ws/index.d.ts#L312
And HTTPServer comes from import { Server as HTTPSServer } from "https";
my Node version is v18.15.0
"@types/ws" from package-lock.json is: "version": "8.5.12"
Here is where it is inherited from:
There is a relative issue https://github.com/web3/web3.js/issues/6303
Rolling back to "@types/ws": "8.5.4" probably fixes the problem
jfyi @2heal1
Do you happen to have any updates on this one? Had the same issue, It happens both on my project and module-federation rs-pack example
because now mf types will use project's tsconfig.json , so you can set "skipLibCheck": true, in tsConfig.json compilerOptions to prevent the error
because now mf types will use project's tsconfig.json , so you can set
"skipLibCheck": true,in tsConfig.json compilerOptions to prevent the error
I have this in my tsconfig. The same error is still there.. Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json' Error: ENOENT: no such file or directory, open '/Users/xxxx/dist/@mf-types.zip'
I have this in my tsconfig. The same error is still there.. Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json' Error: ENOENT: no such file or directory, open '/Users/xxxx/dist/@mf-types.zip'
Try to run the specified command from the error message (in your case it is npx tsc --project /Users/xxxx/zzzz/node_modules/.federation/tsconfig.6dd5cd1b6230eccdafd02f44d0cfb6a2.json) and see what the TSError looks like
Describe the bug
GenerateTypesPluginis having trouble generating the zip file for@mf-types.Replication is just bumping the plugins version to
0.3.3of an rspack app from mf examples repo.
.
Reproduction
https://github.com/module-federation/module-federation-examples/tree/master/rspack_hmr/app2
Used Package Manager
pnpm
System Info
System: OS: macOS 14.5 CPU: (10) arm64 Apple M2 Pro Memory: 213.69 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm pnpm: 9.5.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm Browsers: Chrome: 127.0.6533.89 Safari: 17.5Validations
- [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.
Hi guys, I'm also experiencing this problem, when I run pnpm dev and when generating @mf-types type, it reports Error: ENOENT: no such file or directory, open xxx/mf-demo/federation_provider/dist/@mf- types.zip'. After checking, I found that there is no coustom.zip file in the dist directory.
After troubleshooting, we found that there is an error reported for ts types in the project, @my-types.zip generation failed.
error ts:
Then stamp the ts type so he doesn't report errors, and you can generate the @mf-types.zip file
@ryok90 upgrade to 0.6.5 , the issue should be fixed , if still has error , please tell me , i will fix it soon
I'm still facing this issue for vue project:
import { defineConfig } from "@rsbuild/core";
import { pluginVue } from "@rsbuild/plugin-vue";
import { ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
export default defineConfig({
plugins: [pluginVue()],
dev: {
assetPrefix: true,
},
tools: {
rspack: {
output: {
uniqueName: "vue_mfe_app",
},
plugins: [
new ModuleFederationPlugin({
name: "vue_mfe_app",
exposes: {
"./App": "./src/App.vue",
},
shared: ["vue"],
filename: "remoteEntry.js",
}),
],
},
},
});
Note the line "./App": "./src/App.vue",
Unable to compile federated types, Error: compile TS failed, the original command is 'npx tsc --project /Users/bytedance/Code/Personal/mfe-multi-bundlers/vue-mfe-app/node_modules/.federation/tsconfig.425616e1a5a10887de70d1a4135651e6.json'
We've upgraded to this version and can confirm that the types are now generated as expected.
For those still facing this issue: Ensure you do not have Typescript errors within your project. When we had errors this lead to the mf-types.zip not being generated. If that file was missing for a remote app, the host app would then delete the types of the remote app from its mf-types folder too. So ensure there are no Typescript errors in any of your applications.
I came across this issue as well and was able to resolve by changing the exposed path from the root of the project to it's relative path. The problem was hard to identify because using the path from the root of the project worked when the type generation was disabled.
Configuration that caused the failure:
new ModuleFederationPlugin({
....
exposes: { './Foo': '/src/components/Foo.tsx' },
...
})
Fixed configuration:
new ModuleFederationPlugin({
....
exposes: { './Foo': './src/components/Foo.tsx' },
...
})
Yeah. Same rules as package.json exports field
In my point of view the solution is already addressed here by:
- @2heal1 (version update + solution path to adding custom strategy runtime plugin)
- @pganster (ensure clean build by resolving all TS issues beforehand)
- @jeremy-leclerc (making sure the exposes field is poperly set)
I will write a short doc for this on the Error Catalog guide After that we can close this issue.
Docs updated, issue can be closed
Just in case it helps someone else coming here. I was having the same issue, but it was due to the fact that I already had a tsconfig.json in the directory (which it extends when found) which had some settings that conflicted with what it expected.
Also worth pointing out that even once I fixed that and the types generated properly on the first run without errors, every subsequent run generated a new tsconfig file and appended the newly generated types as files into the files list, which then promptly errors out:
Second run generated a tsconfig which has the previously generated .d.ts files:
{
"extends": "/Users/arimus/workspace/dynamic-remotes-node/remote/tsconfig.json",
"compileOnSave": false,
"compilerOptions": {
"rootDir": "/Users/arimus/workspace/dynamic-remotes-node/remote",
"emitDeclarationOnly": true,
"noEmit": false,
"declaration": true,
"outDir": "/Users/arimus/workspace/dynamic-remotes-node/remote/dist/@mf-types/compiled-types"
},
"include": [],
"files": [
"/Users/arimus/workspace/dynamic-remotes-node/remote/src-js/expose-sample.js",
"/Users/arimus/workspace/dynamic-remotes-node/remote/dist/@mf-types.d.ts",
"/Users/arimus/workspace/dynamic-remotes-node/remote/src-js/expose-sample.d.ts"
],
"exclude": []
}
Manually re-running the tsc command gives:
npx tsc --project /Users/arimus/workspace/dynamic-remotes-node/remote/node_modules/.federation/tsconfig.db9093e72f99b2653ae903ff6c203eea.json
remote/dist/@mf-types.d.ts:3:86 - error TS2307: Cannot find module 'REMOTE_ALIAS_IDENTIFIER/sample' or its corresponding type declarations.
3 type PackageType<T> = T extends 'REMOTE_ALIAS_IDENTIFIER/sample' ? typeof import('REMOTE_ALIAS_IDENTIFIER/sample') :any;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in remote/dist/@mf-types.d.ts:3
I can open a new ticket if you guys want to track this issue separately, but wanted to get here for visibility. Technically, most folks won't run into this unless they have a tsconfig.json for some reason in a JS project that's being webpack'd without transpilation. I ran into it because I have a project where I'm doing both examples. That said, it's pretty easy to run into this issue accidentally when trying diff things out, so worth documenting here anyways.
Interesting case. I will try to reproduce it and add it to the docs. Thanks for the investigation @arimus !
I'm following the quick start guide at https://module-federation.io/guide/start/quick-start.html.
Trying the build or dev commands gives me the following error:
Executing task: npm run build
> [email protected] build
> rsbuild build
Rsbuild v1.1.14
β web βββββββββββββββββββββββββ (74%) sealing after module optimization [ Module Federation Dev Server ] Error Unable to compile federated typesError: Failed to generate type declaration. #TYPE-001
args: {"cmd":"npx tsc --project C:\\Projects\\module-federation\\federation_provider\\node_modules\\.federation\\tsconfig.640b668e9bc1c113939670178a7a6d19.json"}
https://module-federation.io/guide/troubleshooting/type/TYPE-001
Error in mf:generateTypes processAssets hook: Error: ENOENT: no such file or directory, open 'C:\Projects\module-federation\federation_provider\dist\@mf-types.zip'
at Object.openSync (node:fs:562:18)
at Object.readFileSync (node:fs:446:35)
at _GenerateTypesPlugin.<anonymous> (C:\Projects\module-federation\federation_provider\node_modules\@module-federation\dts-plugin\dist\index.js:2610:141)
at Generator.next (<anonymous>)
at fulfilled (C:\Projects\module-federation\federation_provider\node_modules\@module-federation\dts-plugin\dist\index.js:66:24)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Projects\\module-federation\\federation_provider\\dist\\@mf-types.zip'
}
β web βββββββββββββββββββββββββ (100%) emitting after emit ready Built in 1.35 s (web)
File (web) Size Gzip
dist\index.html 0.31 kB 0.22 kB
dist\static\css\async\677.54800c1b.css 0.34 kB 0.25 kB
dist\static\js\async\677.9166d63a.js 0.46 kB 0.31 kB
dist\static\js\async\__federation_expose_button.3eb4437a.js 0.71 kB 0.46 kB
dist\mf-manifest.json 1.9 kB 0.48 kB
dist\mf-stats.json 2.1 kB 0.54 kB
dist\static\js\async\259.84da31e1.js 3.7 kB 1.4 kB
dist\static\js\async\987.1c234709.js 3.7 kB 1.4 kB
dist\static\js\index.7fe2f0d7.js 5.3 kB 2.3 kB
dist\static\js\async\512.f33d498f.js 7.5 kB 2.9 kB
dist\static\js\341.920f9f5e.js 75.1 kB 22.7 kB
dist\static\js\federation_provider.f3fd28c8.js 80.3 kB 24.2 kB
dist\static\js\async\339.9651f857.js 171.2 kB 54.5 kB
Total: 352.7 kB (gzip: 111.7 kB)
I tried running the command npx tsc --project "C:\Projects\module-federation\federation_provider\node_modules.federation\tsconfig.640b668e9bc1c113939670178a7a6d19.json" as suggested in https://module-federation.io/guide/troubleshooting/type/TYPE-001 and I am not getting any error and the file 'federation_provider\dist@mf-types\compiled-types\button.d.ts' is generated. Trying to build or run dev again, the file is removed and the error occurs again.
.