vite icon indicating copy to clipboard operation
vite copied to clipboard

fix: don't try to discover shared item version in case of custom version or invalid package name

Open mshima opened this issue 1 year ago • 4 comments

Exposing a local share causes lots of errors in console:

Error: Cannot find module '@/package.json'
Require stack:
- /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at normalizeShareItem (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:296:15)
    at /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:335:21
    at Array.forEach (<anonymous>)
    at normalizeShared (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:334:25)
    at normalizeModuleFederationOptions (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:379:13)
    at federation (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:1236:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs'
  ]
}
Error: Cannot find module '@/package.json'
Require stack:
- /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at normalizeShareItem (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:296:15)
    at /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:335:21
    at Array.forEach (<anonymous>)
    at normalizeShared (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:334:25)
    at normalizeModuleFederationOptions (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:379:13)
    at federation (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:1236:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs'
  ]
}
Error: Cannot find module '@/package.json'
Require stack:
- /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at normalizeShareItem (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:296:15)
    at /Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:335:21
    at Array.forEach (<anonymous>)
    at normalizeShared (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:334:25)
    at normalizeModuleFederationOptions (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:379:13)
    at federation (/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs:1236:17) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/mshima/git/jhipster-samples/vite-mf/notification/node_modules/@module-federation/vite/lib/index.cjs'
  ]
}

mshima avatar Oct 03 '24 21:10 mshima

How to configure “shared”? Do Webpack or Rust have this feature?

zhangHongEn avatar Oct 05 '24 02:10 zhangHongEn

Understood, I will review it later.

zhangHongEn avatar Oct 05 '24 02:10 zhangHongEn

Thank you for your contribution, but this feature requires some additional handling, and I will complete it this week.

zhangHongEn avatar Oct 07 '24 15:10 zhangHongEn

There is one more step left for the proxy logic to convert relative paths to absolute paths. I will find time this week to complete it.​

zhangHongEn avatar Oct 07 '24 16:10 zhangHongEn

Are there any news on this one?

gioboa avatar Oct 21 '24 09:10 gioboa

I've been really busy lately, working overtime for the weekend and not being able to handle this issue in a timely manner

---- Replied Message ---- | From | Giorgio @.> | | Date | 10/21/2024 17:39 | | To | module-federation/vite @.> | | Cc | zhn @.>, Comment @.> | | Subject | Re: [module-federation/vite] fix: don't try to discover shared item version in case of custom version or invalid package name (PR #131) |

Are there any news on this one?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

zhangHongEn avatar Oct 21 '24 14:10 zhangHongEn

Maybe shared management should be handled by https://github.com/module-federation/core/blob/main/packages/managers/src/SharedManager.ts

mshima avatar Oct 21 '24 14:10 mshima

Maybe shared management should be handled by https://github.com/module-federation/core/blob/main/packages/managers/src/SharedManager.ts

Yes, unifying the logic is better. You can submit a PR to fix this issue, but implementing shared relative paths will be different from the current process of sharing npm packages.

zhangHongEn avatar Oct 21 '24 14:10 zhangHongEn

I really don’t have time to add this feature, but can use Delegate Modules.

zhangHongEn avatar Oct 29 '24 11:10 zhangHongEn

or use shared-library https://github.com/module-federation/module-federation-examples/tree/master/shared-context

zhangHongEn avatar Oct 29 '24 11:10 zhangHongEn

I'm closing this for now because it's stale and with conflicts, feel free to create a new PR with your improvements. :muscle: Thanks for your help @mshima :pray:

gioboa avatar Feb 05 '25 09:02 gioboa