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.

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

See original GitHub issue

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:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

9reactions
vugar005commented, Jan 20, 2022

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

 shared: {
  "@angular/core": {
   singleton: true,
   strictVersion: true,
   requiredVersion: '12.0.0'
 },
   "@angular/common": {
   singleton: true,
   strictVersion: true,
   requiredVersion: '12.0.0'
 },
   "@angular/common/http": {
   singleton: true,
   strictVersion: true,
   requiredVersion: '12.0.0'
 },
   "@angular/router": {
   singleton: true,
   strictVersion: true,
   requiredVersion: '12.0.0'
 },

 },
2reactions
arrgsoncommented, Jun 22, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Unexpected value 'undefined' imported by the module
The issue is that there is at least one import for which source file is missing. For example I got ...
Read more >
6. Modules — Python 3.11.1 documentation
Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the...
Read more >
What Happens When a Module Is Imported Twice?
A JavaScript module is evaluated just once. When imported multiple times from the same path, the same module instance is returned.
Read more >
add_library — CMake 3.25.1 Documentation
New in version 3.11: The source files can be omitted if they are added later using ... For SHARED and MODULE libraries the...
Read more >
Modules — Clang 16.0.0git documentation
Standard C++ Modules; Objective-C Import declaration; Includes as imports ... affect how modules are built, to improve sharing of compiled module files.
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