diff --git a/.changeset/ai-noisy-wolf.md b/.changeset/ai-noisy-wolf.md new file mode 100644 index 00000000000..0b45c838db0 --- /dev/null +++ b/.changeset/ai-noisy-wolf.md @@ -0,0 +1,10 @@ +--- +"@module-federation/cli": patch +--- + +Improve dynamic module import for `readConfig` function to use file URL format. + +- Added `pathToFileURL` import from 'url' module. +- Updated the dynamic import statement for `mfConfig` to use `pathToFileURL(preBundlePath).href`. +- Ensures compatibility and correctness in environments where file paths require URL format. +``` \ No newline at end of file diff --git a/package.json b/package.json index 043ced81c9e..10f9154706e 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "prepare": "husky install", "changeset": "changeset", "build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'", - "changegen": "./changeset-gen.js --path ./packages/enhanced --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged", + "changegen": "./changeset-gen.js --path ./packages/enhanced --staged &&./changeset-gen.js --path ./packages/cli --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged", "commitgen:staged": "./commit-gen.js --path ./packages --staged", "commitgen:main": "./commit-gen.js --path ./packages", "changeset:status": "changeset status", diff --git a/packages/cli/src/utils/readConfig.ts b/packages/cli/src/utils/readConfig.ts index ebbcb78e4a8..4dda30d823d 100644 --- a/packages/cli/src/utils/readConfig.ts +++ b/packages/cli/src/utils/readConfig.ts @@ -1,6 +1,7 @@ import path from 'path'; import { bundle } from '@modern-js/node-bundle-require'; import type { moduleFederationPlugin } from '@module-federation/sdk'; +import { pathToFileURL } from 'url'; const DEFAULT_CONFIG_PATH = 'module-federation.config.ts'; @@ -15,7 +16,7 @@ export const getConfigPath = (userConfigPath?: string) => { export async function readConfig(userConfigPath?: string) { const configPath = getConfigPath(userConfigPath); const preBundlePath = await bundle(configPath); - const mfConfig = (await import(preBundlePath)).default + const mfConfig = (await import(pathToFileURL(preBundlePath).href)).default .default as unknown as moduleFederationPlugin.ModuleFederationPluginOptions; return mfConfig; }