angular-architects / module-federation-plugin

MIT License
683 stars 184 forks source link

Unable to resolve specifier 'lodash/fp' imported from ... #526

Closed alaindeurveilher closed 2 weeks ago

alaindeurveilher commented 1 month ago

Hello,

I am trying to build up a MFE application with Native Federation (v17.1.7)

I have a shell. I have a remote defined in a different repository.

In my remote I have a service which uses some functions from lodash/fp My shell does not use lodash/fp, so lodash is naturally not present in its package.json file.

Now, when I load the remote in the shell I get the following error on runtime in the console:

_angular_core-17_3_0-dev.js:3806 ERROR Error: Unable to resolve specifier 'lodash/fp' imported from http://localhost:5202/Routes.js
    at throwUnresolved (es-module-shims.js:445:11)
    at _resolve (es-module-shims.js:402:71)
    at es-module-shims.js:850:32
    at Array.map (<anonymous>)
    at es-module-shims.js:846:45
    at _ZoneDelegate.invoke (zone.js:368:26)
    at _Zone.run (zone.js:130:43)
    at zone.js:1260:36
    at _ZoneDelegate.invokeTask (zone.js:403:31)
    at _Zone.runTask (zone.js:174:47)

Example:

import { getOr } from 'lodash/fp';
...

let message: string = getOr(path, path, I18S[this.language()]);
  shared: {
    ...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
    ...share({
      'lodash/fp': { singleton: true, strictVersion: true, requiredVersion: 'auto' },
    }),
  },

But it did not solve the problem.

    {
      "packageName": "lodash",
      "outFileName": "lodash-4_17_21-dev.js",
      "requiredVersion": "^4.17.21",
      "singleton": true,
      "strictVersion": true,
      "version": "4.17.21",
      "dev": {
        "entryPoint": "C:/Users/XXXX/workspace/mfe-app/node_modules/lodash/lodash.js"
      }

...

    {
      "packageName": "/@id/lodash",
      "outFileName": "lodash-4_17_21-dev.js",
      "requiredVersion": "^4.17.21",
      "singleton": true,
      "strictVersion": true,
      "version": "4.17.21",
      "dev": {
        "entryPoint": "C:/Users/XXXX/workspace/mfe-app/node_modules/lodash/lodash.js"
      }

Could you please help fixing the issue?

Thank you.

manfredsteyer commented 2 weeks ago

It's a commonjs vs. esm issue. Please look here: https://github.com/angular-architects/module-federation-plugin/issues/460