question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack 5 ModeFederation error when shared package version is not in semver

See original GitHub issue

Bug report

What is the current behavior? One of our packages has version ‘dev’ set in package.json as it is internal not released yet package.

....
"dependencies": {
    "{PACKAGE_NAME}": "dev",
}
....

When I try to configure ModeFederationPlugin for our main app I configure shared modules as follows:

const packageJson = require('../package.json');

const packageName = packageJson.name;
const packageDeps = packageJson.dependencies;

new ModuleFederationPlugin({
   ....
    shared: {
      ...packageDeps,
      react: {
        singleton: true,
        eager: true,
        requiredVersion: packageDeps.react,
      },
      'react-dom': {
        singleton: true,
        eager: true,
        requiredVersion: packageDeps['react-dom'],
      },
    },
    ....
  }),

When I run webpack it gives me next error:

ERROR in resolving fallback for shared module ($PACKAGE_NAME}
Module not found: Error: Can't resolve 'dev' in '{PATH_TO_FILE_USING_PACKAGE}'

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

  1. Add package with version different from semantic versioning standard to dependencies of the project
  2. Try to add ModuleFederationPlugin to the webpack config of the app with the following config:
const packageJson = require('../package.json');

const packageName = packageJson.name;
const packageDeps = packageJson.dependencies;

new ModuleFederationPlugin({
    name: packageName,
    remotes: {},
    shared: {
      ...packageDeps,
      angular: {
        singleton: true,
        eager: true,
        requiredVersion: packageDeps.angular,
      },
      react: {
        singleton: true,
        eager: true,
        requiredVersion: packageDeps.react,
      },
      'react-dom': {
        singleton: true,
        eager: true,
        requiredVersion: packageDeps['react-dom'],
      },
    },
  }),
  1. Run webpack and see the errors in the console

What is the expected behavior? I assume that if webpack can resolve node_modules with non-semantic versioning then ConsumeSharedPlugin should also be able to

If any additional info is needed for me, please let me know

Other relevant information: webpack version: 5.24.4 Node.js version: v14.15.0 Operating System: macOS Catalina Version 10.15.7 Additional tools:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Apr 19, 2021

We have logic to detect singleton problems with multiple versions, so each package should have valid (parsable by semver) version

0reactions
webpack-botcommented, Aug 4, 2021

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document webpack change: Versioned shared modules for ...
The new system is based on versions of shared modules. In group of federated builds all parts will agree on the highest version...
Read more >
Getting Out of Version-Mismatch-Hell with Module Federation
This shows that Module Federation uses different versions for both applications.
Read more >
webpack reads wrong dependency versions from package ...
Inside my Module Federation setup I have a host application that consumes a few remote apps. They all share the angular ...
Read more >
Module Federation - webpack
This object is used as a shared scope in the remote container and is filled with the provided modules from a host. It...
Read more >
Semantic Versioning 2.0.0 | Semantic Versioning
0. Summary. Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes; MINOR ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found