Skip to content

Resolve module (mjs) incorrectly when using Module Federation Plugin #16125

Description

@tzachbon

Bug report

What is the current behavior?

When using swr/infinite with swr>1.1.2 dependency and sharing it with Module Federation (SharePlugin)

    new webpack.container.ModuleFederationPlugin({
      shared: ['swr'],
    }),

We encountered this error:
with-mf

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

I created this repo that reproduces the issue: https://github.com/tzachbon/swr-mf-error

All you have to do is to use SWR >= 1.2.0 and add it to the shared array in the Module Federation Plugin.
In the change log here: vercel/swr@1.1.2...1.2.0
I found a few things that might be the reason.

In my code, I try to import swr/infinite, which now has exports field in its package json:

  "exports": "./dist/index.mjs",

In the swr package json, the exports field now has a filename that ends with mjsextension:

    "./infinite": {
      "import": "./infinite/dist/index.mjs",
      "module": "./infinite/dist/index.esm.js",
      "require": "./infinite/dist/index.js",
      "types": "./infinite/dist/infinite/index.d.ts"
    },

When I manually changed the filename to .js it worked.

What is the expected behavior?

To resolve it like .js

Other relevant information:
webpack version: 5.74.0
Node.js version: 16.15.0
Operating System: MacBook Pro (16-inch, 2021)
Additional tools: swr: 1.3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedMaintainers welcome a community PR for thiswebpack-5Concerns the webpack 5 line

    Type

    No type

    Fields

    Priority

    None yet

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions