Skip to content
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

Module federation warns "Unable to find required version" when using package self referencing #16683

Closed
weareoutman opened this issue Jan 30, 2023 · 0 comments · Fixed by #16685

Comments

@weareoutman
Copy link
Contributor

weareoutman commented Jan 30, 2023

Bug report

What is the current behavior?

In an esm package, I have two modules, one imports another by self referencing

{
  "name": "my-pkg",
  "type": "module",
  "exports": {
    "./module-a": "./module-a.js",
    "./module-b": "./module-b.js"
  }
}
// module-a.js
export function a() {}
// module-b.js
import { a } from "my-pkg/module-a";

export function b() {
  return a();
}

In another app, I use module federation and share the two modules:

// Partial webpack.config.js
new ModuleFederationPlugin({
  shared: {
    "my-pkg/module-a": {
      singleton: true,
      version: "1.0.0"
    },
    "my-pkg/module-b": {
      singleton: true,
      version: "1.0.0"
    },
  }
});

When I start the dev-server, it reports a warning of:

WARNING in shared module my-pkg/module-a
No required version specified and unable to automatically determine one. Unable to find required version for "my-pkg" in description file (.../packages/my-pkg/package.json). It need to be in dependencies, devDependencies or peerDependencies.

And according to the warning, I added the package itself as a dependency, the warning disappears:

{
  "name": "my-pkg",
  "type": "module",
  "exports": {
    "./module-a": "./module-a.js",
    "./module-b": "./module-b.js"
  },
  "dependencies": {
    "my-pkg": "*" // It's weird to do this...
  }
}

If the current behavior is a bug, please provide the steps to reproduce.

It's a bit complex in my real repo, I can provide a minimal repro if you require, when I got time.

What is the expected behavior?

No warnings. It should use the description file (my-pkg/package.json) itself to determine the required version, since it's a self referencing.

Other relevant information:
webpack version: 5.75.0
Node.js version: 16.15.0
Operating System: MacOS
Additional tools:

weareoutman added a commit to weareoutman/webpack that referenced this issue Jan 31, 2023
thet added a commit to Patternslib/Patterns that referenced this issue Apr 17, 2023
The Module federation warning "Unable to find required version" is fixed
since webpack v5.78.0 for modules which do package.json
self-referencing.

Ref:
- webpack/webpack#16683
- webpack/webpack#16685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant