Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rubiks-cube opened this issue Oct 9, 2024 · 18 comments · Fixed by #246
Labels
bug Something isn't working COMMUNITY: PR is welcomed We think it's a good feature to have but would love for the community to help with the PR for it help wanted Extra attention is needed

Comments

@rubiks-cube
Copy link

rubiks-cube commented Oct 9, 2024

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
Copy link
Collaborator

gioboa commented Oct 9, 2024

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

@rubiks-cube
Copy link
Author

rubiks-cube commented Oct 9, 2024

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

@gioboa
Copy link
Collaborator

gioboa commented Oct 9, 2024

This is something wrong in the d3 package, in fact, I found an issue in their repo.
Unfortunately this is an old problem d3/d3#3556

@gioboa gioboa changed the title Dependency with different entry points is throwing error when added as shared dependency share d3 package: error Package subpath './package.json' is not defined by "exports" Oct 10, 2024
@gioboa
Copy link
Collaborator

gioboa commented Oct 10, 2024

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

@gioboa gioboa closed this as completed Oct 10, 2024
@rubiks-cube
Copy link
Author

rubiks-cube commented Oct 10, 2024

@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
Copy link
Collaborator

gioboa commented Oct 10, 2024

Can you give me one or two examples pls?

@rubiks-cube
Copy link
Author

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

@gioboa
Copy link
Collaborator

gioboa commented Oct 10, 2024

Nice, I'll take a look

@rubiks-cube
Copy link
Author

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
Copy link
Collaborator

gioboa commented Oct 15, 2024

You are right. Let's re-open it

@gioboa gioboa reopened this Oct 15, 2024
@gioboa gioboa changed the title share d3 package: error Package subpath './package.json' is not defined by "exports" share chart.js package: error Package subpath './package.json' is not defined by "exports" Oct 15, 2024
@gioboa gioboa added bug Something isn't working help wanted Extra attention is needed COMMUNITY: PR is welcomed We think it's a good feature to have but would love for the community to help with the PR for it labels Oct 15, 2024
@pkorneev
Copy link

pkorneev commented Nov 4, 2024

Hey, are there any updates on this?

@gioboa
Copy link
Collaborator

gioboa commented Nov 4, 2024

Hey, are there any updates on this?

No one is working on it, as far as I know. Feel free to help us if you like.

@ScriptedAlchemy
Copy link
Member

Dirty hack, but can you patch the package.jsons of the affected packages?

@nicotu01
Copy link
Contributor

nicotu01 commented Dec 7, 2024

I propose this workaround #216

@irwinarruda
Copy link
Contributor

I also have this issue migrating an old Webpack MF project to Vite. More examples react-chartjs-2, react-dropzone, react-easy-crop, sass.

@gioboa
Copy link
Collaborator

gioboa commented Dec 11, 2024

Hi @irwinarruda
Is #216 working for you? Can you give it a try?
You can modify your node_modules manually and test

@irwinarruda
Copy link
Contributor

@gioboa, I’ve left a comment in the PR.

@gioboa
Copy link
Collaborator

gioboa commented Feb 3, 2025

Closed by #246

@gioboa gioboa closed this as completed Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working COMMUNITY: PR is welcomed We think it's a good feature to have but would love for the community to help with the PR for it help wanted Extra attention is needed
Projects
None yet
6 participants