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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mshima
Copy link
Contributor

@mshima mshima commented Oct 3, 2024

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 mshima marked this pull request as draft October 3, 2024 21:15
@mshima mshima closed this Oct 4, 2024
@mshima mshima reopened this Oct 4, 2024
@mshima mshima changed the title fix: do not show stack trace if shared resource is a internal share. fix: don't try to discover shared item version in case of custom version and invalid package name Oct 4, 2024
// 匹配npm包名的正则表达式,忽略路径部分
const regex = /^(?:@[^/]+\/)?[^/]+/;
const regex = /^(?:@[^/]+\/)?\w[^/]+/;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A valid package starts with a letter.

console.log(e);
let { version, requiredVersion }: any = typeof shareItem === 'object' ? shareItem : {};
if (!version) {
const npmPackage = removePathFromNpmPackage(key);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliases probably should take precedence over packages.

options.shared[removePathFromNpmPackage(key)] ||
options.shared[removePathFromNpmPackage(key) + '/'];
return shareItem;
return options.shared[key];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removePathFromNpmPackage() doesn't looks to be applied when creating the shared object.

@mshima mshima marked this pull request as ready for review October 4, 2024 18:28
@mshima mshima changed the title fix: don't try to discover shared item version in case of custom version and invalid package name fix: don't try to discover shared item version in case of custom version or invalid package name Oct 4, 2024
@zhangHongEn
Copy link
Contributor

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

@zhangHongEn
Copy link
Contributor

Understood, I will review it later.

@zhangHongEn
Copy link
Contributor

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

zhangHongEn added a commit to zhangHongEn/vite that referenced this pull request Oct 7, 2024
zhangHongEn added a commit to zhangHongEn/vite that referenced this pull request Oct 7, 2024
@zhangHongEn
Copy link
Contributor

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.​

@gioboa
Copy link
Collaborator

gioboa commented Oct 21, 2024

Are there any news on this one?

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Oct 21, 2024 via email

@mshima
Copy link
Contributor Author

mshima commented Oct 21, 2024

@zhangHongEn
Copy link
Contributor

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

zhangHongEn commented Oct 29, 2024

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

@zhangHongEn
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants