Skip to content

Undetermined shared module version when importing a file from the module directly #13457

@Hornwitser

Description

@Hornwitser

Bug 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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions