-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve module (mjs) incorrectly when using Module Federation Plugin #16125
Comments
Add some addition infomration: The esm assets of swr ( If I removed the |
You can skip this issue by also sharing any submodule of swr changing this:
to this
|
@keropodium Thanks! I checked, it resolved the issue! cc @tzachbon |
Thanks! It does work but isn't it a workaround for an existing bug with the resolution? |
@tzachbon Correct, this issue still needs to be addressed. |
I think it may be a bug if the default isn’t resolving to something. If you’re doing a “deep” import into the package. Then trailing slash is needed |
1 we just found this bug
I'm not sure from the context whether you mean this is a bug with swr or webpack?
Is the trailing slash a normal convention or is this a workaround? |
Feel free to send a PR |
I will share my insights after a little more investigating:
I am not sure where |
I think the issue is in that file since webpack resolves correctly. It must be the "result" here which isn't resolved to the right dependency |
Another small breakthrough for me.
The problem is when the consumer extension is I'm not sure where and when the export type should be "dynamic" or "default-with-named", but it looks like when the |
Just gonna add a few keywords here for google, because it took me WEEKS to find this issue:
|
I've created a really small reproduction case of this. I was able to make it happen even with local dependencies. https://github.com/ZenTwipped/webpack-default-repro Just |
I've been able to figure out that the issue is in the detection of exportsType of a shared module when passing through from another shared module, it comes back as |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
Is there anybody more intimate with the container inner workings that can comment on this? The Send a PR tag isn't helpful when nobody is able to work out what's causing it. |
@ScriptedAlchemy would be the main implementor or archetect for MF. I'm sure he could provide some guidance. |
I made a cleaner demo to help you reproduce this bug,https://stackblitz.com/edit/webpack-mf-bug-with-mjs?file=README.md Tese CaseShared package(demo-package) provite index.js/index.mjs/index.esm.js,the default exported file is index.js. index.js: class AClass {
constructor() {
this.a = 1
}
install() {
console.log('this.a', this.a)
}
}
module.exports = AClass index.mjs/index.esm.js: export default class AClass {
constructor() {
this.a = 1
}
install() {
console.log('this.a', this.a)
}
} Case1In app-a webpack.config.js const path = require('path');
const { ModuleFederationPlugin } = require('webpack').container
module.exports = {
entry: './src/index.js',
mode: 'development',
target: 'node',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
alias: {},
},
plugins: [
new ModuleFederationPlugin({
name: 'webpack-mf-bug-with-mjs',
library: { type: 'var', name: 'webpack-mf-bug-with-mjs' },
filename: 'remoteEntry.js',
shared: ['demo-package'],
}),
],
}; The result of running bundle file is: packages/app-a test: AClass from test.mjs: [class AClass]
packages/app-a test: AClass from test.js: [class AClass] Case2In app-b, change config to export a mjs or .esm.js file from demo-package. webpack.config.js const path = require('path');
const { ModuleFederationPlugin } = require('webpack').container
module.exports = {
entry: './src/index.js',
mode: 'development',
target: 'node',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
alias: {
'demo-package': 'demo-package/index.mjs'
// NOTE: .esm.js file got the same result
// 'demo-package': 'demo-package/index.esm.js'
},
},
plugins: [
new ModuleFederationPlugin({
name: 'webpack-mf-bug-with-mjs',
library: { type: 'var', name: 'webpack-mf-bug-with-mjs' },
filename: 'remoteEntry.js',
shared: ['demo-package'],
}),
],
}; The result of running bundle file is: packages/app-b test: AClass from test.mjs: Object [Module] { default: [Getter] }
packages/app-b test: AClass from test.js: [class AClass] Got an unexpected result in test.mjs Case3In app-c, do not share package, everything is normal. webpack.config.js const path = require('path');
const { ModuleFederationPlugin } = require('webpack').container
module.exports = {
entry: './src/index.js',
mode: 'development',
target: 'node',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
alias: {
'demo-package': 'demo-package/index.mjs'
//NOTE: .esm.js file got the same result
// 'demo-package': 'demo-package/index.esm.js'
},
},
plugins: [
new ModuleFederationPlugin({
name: 'webpack-mf-bug-with-mjs',
library: { type: 'var', name: 'webpack-mf-bug-with-mjs' },
filename: 'remoteEntry.js',
// NOTE: Don't share the package, you will get the desired result
// shared: ['demo-package'],
}),
],
}; The result of running bundle file is: packages/app-c test: AClass from test.mjs: [class AClass]
packages/app-c test: AClass from test.js: [class AClass] |
Yeah, looks like a bug, someone wants to send a PR? |
I don't mind but can somebody guide me on where to focus? |
I'm certainly no expert in how everything weaves together but if this is a question of resolution and it appears to be triggered by shared according to the bug replication by @hangboss1761 I would say a good starting place is here (The link will open the GitHub dev editor) Relative path in code: I don't have time to take a deep dive at the moment but hopefully, that helps @tzachbon Later I can take a look, ran into this I believe after adding the However, I resolved it by setting it back to my UMD build via an explicit path. The trailing slash did not work with my scoped package. If the aforementioned behavior is connected then, it looks like the path came from the ConsumeSharedPlugin. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
Bump |
Bug report
What is the current behavior?
When using
swr/infinite
withswr>1.1.2
dependency and sharing it with Module Federation (SharePlugin)We encountered this error:
If the current behavior is a bug, please provide the steps to reproduce.
I created this repo that reproduces the issue: https://github.com/tzachbon/swr-mf-error
All you have to do is to use SWR >= 1.2.0 and add it to the shared array in the Module Federation Plugin.
In the change log here: vercel/swr@1.1.2...1.2.0
I found a few things that might be the reason.
In my code, I try to import
swr/infinite
, which now has exports field in its package json:In the
swr
package json, the exports field now has a filename that ends withmjs
extension:When I manually changed the filename to
.js
it worked.What is the expected behavior?
To resolve it like
.js
Other relevant information:
webpack version: 5.74.0
Node.js version: 16.15.0
Operating System: MacBook Pro (16-inch, 2021)
Additional tools: swr: 1.3.0
The text was updated successfully, but these errors were encountered: