module-federation / vite

Vite Plugin for Module Federation
MIT License
297 stars 21 forks source link

share `chart.js` package: error Package subpath './package.json' is not defined by "exports" #152

Open rubiks-cube opened 1 week ago

rubiks-cube commented 1 week ago

In the federation plugin when adding a dependency which has multiple exports paths, as shared dependency in remote like this:

federation({ 
      name: "remoteapp",  
      filename: "remoteEntry.js",  
      remotes: {},  
      exposes: {. 
        './RemoteApp: './src/bootstrap',  
      },  
      shared: {. 
        "some-package-name":"1.0.0". 
     } 
})

getting following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in \node_modules\<some-package>\package.json
    at exportsNotFound (node:internal/modules/esm/resolve:304:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:651:9)
    at resolveExports (node:internal/modules/cjs/loader:592:36)
    at Module._findPath (node:internal/modules/cjs/loader:669:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1131:27)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at normalizeShareItem ()
    at C:\Users\\Desktop\vite\UI\node_modules\@module-federation\vite\lib\index.cjs:320:21 {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Vite version : 5.4.8 Node.js: 20.16.0

gioboa commented 1 week ago

Hi, thanks for your interest in the project. Can you create a basic reproduction repository please?

rubiks-cube commented 1 week ago

@gioboa https://github.com/rubiks-cube/my-app/blob/main/vite.config.ts

gioboa commented 1 week ago

This is something wrong in the d3 package, in fact, I found an issue in their repo. Unfortunately this is an old problem https://github.com/d3/d3/issues/3556

gioboa commented 1 week ago

There's not much to say here, we can't do anything because the issue is on d3 package. Thanks.

rubiks-cube commented 1 week ago

@gioboa If some package which has multiple export paths, and it doesn't have package.json in exports like:

"exports": {
    "./package.json": "./package.json",

  },

then only adding those packages in shared is causing above issue. This I have tried with several dependencies.

But the same package with no package.json as export but other export paths is working fine with webpack module federation plugin but not with the vite federation plugin. Not sure what exactly the issue is. This is not just issue with using d3 only but other packages too which has no package.json export but other export paths

gioboa commented 1 week ago

Can you give me one or two examples pls?

rubiks-cube commented 1 week ago

@gioboa for e.g chalk , chart.js, ramda

gioboa commented 1 week ago

Nice, I'll take a look

rubiks-cube commented 4 days ago

any update on this issue? can we reopen this issue as it is not limited to d3? as a workaround for now I also added package.json in export paths for package that I was importing, and we own this package, so it was ok but looking for proper solution. I gave d3 just an example.

gioboa commented 4 days ago

You are right. Let's re-open it