Undetermined shared module version when importing a file from the module directly
See original GitHub issueBug report
What is the current behavior?
When importing a file directly from a module (i.e. import "react-dom/test-utils"
) when it’s configured to be shared via ModuleFedrationPlugin a warning with a nonsensical instruction may be emitted when running a build:
WARNING in shared module react-dom
No required version specified and unable to automatically determine one. Unable to find required version for "react-dom" in description file (/home/user/test/node_modules/react-dom/package.json). It need to be in dependencies, devDependencies or peerDependencies.
If the current behavior is a bug, please provide the steps to reproduce.
Using the following webpack config
"use strict";
const path = require("path");
const webpack = require("webpack");
module.exports = (env = {}) => ({
entry: "./index.js",
output: {
publicPath: "auto",
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
},
mode: "production",
plugins: [
new webpack.container.ModuleFederationPlugin({
name: "test",
shared: {
"react-dom": { singleton: true },
},
}),
],
});
And an index.js file with the content
import "react-dom/test-utils"
Along with a package.json file with the dependencies described in reproduces the behaviour. See the complete example in this repository.
What is the expected behavior?
I expect either the version of react-dom to be correctly deduced from package.json or a sensible warning/error message.
Other relevant information: webpack version: 5.37.1 Node.js version: 16.0.0 Operating System: Arch Linux Additional tools:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:19 (9 by maintainers)
Top GitHub Comments
@arrgson It is because of secondary point. According to manfred amazing book. The reason for this is the secondary entry point
@angular/common/http
which is a bit like an npm package within an npm package. Technically, it’s just another file exposed by the npm package@angular/common
. Unsurprisingly,@angular/common/http
uses@angular/common
and webpack recognizes this. For this reason, webpack wants to find out which version of@angular/common
is used. For this, it looks into the npm package’s package.json ( @angular/common/package.json ) and browses the dependencies there. However,@angular/common
itself is not a depdency of@angular/common
and hence,the version cannot be found. You will have the same challenge with other packages using secondary entry points,e.g. @angular/material . To avoid this situation, you can assign versions to all shared libraries manually:I have the same issue happening with @angular/common .
shared module @angular/common - Warning: No required version specified and unable to automatically determine one. Unable to find required version for "@angular/common" in description file (.../node_modules/@angular/common/package.json). It need to be in dependencies, devDependencies or peerDependencies.
In the package.json file there is no entry for @angular/common under those properties.