remote-components 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/{component-loader-e5513139.d.ts → component-loader-28ad0083.d.ts} +1 -0
  2. package/dist/html/host.cjs +152 -56
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +152 -56
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/internal/next/host/app-router-client.cjs +6 -2
  7. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  8. package/dist/internal/next/host/app-router-client.d.ts +2 -2
  9. package/dist/internal/next/host/app-router-client.js +6 -2
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/remote/render-client.cjs +13 -3
  12. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  13. package/dist/internal/next/remote/render-client.js +13 -3
  14. package/dist/internal/next/remote/render-client.js.map +1 -1
  15. package/dist/internal/next/remote/render-server.cjs +22 -3
  16. package/dist/internal/next/remote/render-server.cjs.map +1 -1
  17. package/dist/internal/next/remote/render-server.js +23 -4
  18. package/dist/internal/next/remote/render-server.js.map +1 -1
  19. package/dist/internal/shared/client/remote-component.cjs +82 -45
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.d.ts +9 -2
  22. package/dist/internal/shared/client/remote-component.js +81 -45
  23. package/dist/internal/shared/client/remote-component.js.map +1 -1
  24. package/dist/internal/shared/error.cjs +50 -0
  25. package/dist/internal/shared/error.cjs.map +1 -0
  26. package/dist/internal/shared/error.d.ts +10 -0
  27. package/dist/internal/shared/error.js +24 -0
  28. package/dist/internal/shared/error.js.map +1 -0
  29. package/dist/internal/shared/ssr/dom-flight.cjs +8 -1
  30. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  31. package/dist/internal/shared/ssr/dom-flight.d.ts +2 -1
  32. package/dist/internal/shared/ssr/dom-flight.js +8 -1
  33. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  34. package/dist/internal/shared/ssr/fetch-remote-component.cjs +48 -5
  35. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  36. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  37. package/dist/internal/shared/ssr/fetch-remote-component.js +52 -5
  38. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  39. package/dist/internal/webpack/next-client-pages-loader.cjs +3 -2
  40. package/dist/internal/webpack/next-client-pages-loader.cjs.map +1 -1
  41. package/dist/internal/webpack/next-client-pages-loader.js +3 -2
  42. package/dist/internal/webpack/next-client-pages-loader.js.map +1 -1
  43. package/dist/next/config.cjs +26 -9
  44. package/dist/next/config.cjs.map +1 -1
  45. package/dist/next/config.js +26 -9
  46. package/dist/next/config.js.map +1 -1
  47. package/dist/next/host/client/index.cjs +133 -57
  48. package/dist/next/host/client/index.cjs.map +1 -1
  49. package/dist/next/host/client/index.d.ts +1 -1
  50. package/dist/next/host/client/index.js +133 -57
  51. package/dist/next/host/client/index.js.map +1 -1
  52. package/dist/next/host/pages-router-client.cjs +1 -1
  53. package/dist/next/host/pages-router-client.cjs.map +1 -1
  54. package/dist/next/host/pages-router-client.js +1 -1
  55. package/dist/next/host/pages-router-client.js.map +1 -1
  56. package/dist/next/host/pages-router-server.cjs +4 -3
  57. package/dist/next/host/pages-router-server.cjs.map +1 -1
  58. package/dist/next/host/pages-router-server.js +4 -3
  59. package/dist/next/host/pages-router-server.js.map +1 -1
  60. package/dist/next/index.cjs +4 -2
  61. package/dist/next/index.cjs.map +1 -1
  62. package/dist/next/index.js +4 -2
  63. package/dist/next/index.js.map +1 -1
  64. package/dist/next/remote/pages-router.cjs +1 -1
  65. package/dist/next/remote/pages-router.cjs.map +1 -1
  66. package/dist/next/remote/pages-router.js +1 -1
  67. package/dist/next/remote/pages-router.js.map +1 -1
  68. package/dist/react/index.cjs +42 -11
  69. package/dist/react/index.cjs.map +1 -1
  70. package/dist/react/index.d.ts +2 -2
  71. package/dist/react/index.js +46 -11
  72. package/dist/react/index.js.map +1 -1
  73. package/dist/shared/host/app.cjs +36 -0
  74. package/dist/shared/host/app.cjs.map +1 -0
  75. package/dist/shared/host/app.d.ts +3 -0
  76. package/dist/shared/host/app.js +12 -0
  77. package/dist/shared/host/app.js.map +1 -0
  78. package/dist/shared/host/pages.cjs +36 -0
  79. package/dist/shared/host/pages.cjs.map +1 -0
  80. package/dist/shared/host/pages.d.ts +3 -0
  81. package/dist/shared/host/pages.js +12 -0
  82. package/dist/shared/host/pages.js.map +1 -0
  83. package/dist/shared/remote/app.cjs +32 -0
  84. package/dist/shared/remote/app.cjs.map +1 -0
  85. package/dist/shared/remote/app.d.ts +3 -0
  86. package/dist/shared/remote/app.js +8 -0
  87. package/dist/shared/remote/app.js.map +1 -0
  88. package/dist/shared/remote/pages.cjs +32 -0
  89. package/dist/shared/remote/pages.cjs.map +1 -0
  90. package/dist/shared/remote/pages.d.ts +3 -0
  91. package/dist/shared/remote/pages.js +8 -0
  92. package/dist/shared/remote/pages.js.map +1 -0
  93. package/dist/shared/remote/wrapper.cjs +48 -0
  94. package/dist/shared/remote/wrapper.cjs.map +1 -0
  95. package/dist/shared/remote/wrapper.d.ts +2 -0
  96. package/dist/shared/remote/wrapper.js +25 -0
  97. package/dist/shared/remote/wrapper.js.map +1 -0
  98. package/dist/{types-b8210fd3.d.ts → types-7c207455.d.ts} +1 -1
  99. package/dist/{types-280a3640.d.ts → types-e4a3fa37.d.ts} +1 -0
  100. package/package.json +37 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { basename, dirname, join, relative } from 'node:path';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { configSchema } from 'next/dist/server/config-schema.js';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { transform as webpackTransform } from './webpack';\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image`, and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/image',\n 'next/dist/client/image-component',\n 'next/dist/api/image',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ],\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/router',\n 'next/link',\n 'next/image',\n 'next/script',\n 'next/form',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const generateSharedRemote = (sharedRemote: Set<string>) =>\n `'use client';\\nmodule.exports = { shared: { ${Array.from(sharedRemote)\n .reduce<string[]>((acc, curr) => {\n let path;\n try {\n path = resolve(process.cwd(), curr);\n if (path) {\n path = relative(process.cwd(), path).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // noop\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n acc.push(\n `[${vendorShared[curr] ?? (path ? `'${path}'` : `require.resolve('${curr}')`)}]: '${curr}',`,\n );\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n const generateSharedHost = (sharedHost: Set<string>) =>\n `'use client';\\nmodule.exports = { shared: { ${Array.from(sharedHost)\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/remote',\n 'remote-components/next/host',\n 'remote-components/next/host/pages-router',\n 'remote-components/next/host/client',\n '@remote-components/shared/remote/app',\n '@remote-components/shared/remote/pages',\n '@remote-components/shared/host/app',\n '@remote-components/shared/host/pages',\n ];\n\n const alias = {\n '@remote-components/shared/remote/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n '@remote-components/shared/remote/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n '@remote-components/shared/host/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n '@remote-components/shared/host/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n let projectId =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\n if (!projectId) {\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n projectId = (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback to env‑var above\n }\n }\n\n if (!projectId) {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name?: string;\n };\n projectId = packageJson.name || basename(process.cwd());\n } else {\n projectId = basename(process.cwd());\n }\n }\n\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (process.env.TURBOPACK) {\n if (\n !(configSchema as ZodSchema).safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n // eslint-disable-next-line no-console\n console.error(\n 'You need to use a Next.js version which supports the `turbopack` and `compiler.defineServer` configuration for Turbopack support with Remote Components.',\n );\n process.exit(1);\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n","export function createRemoteWebpackRequireRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n };\n}\n","import type { Compiler, RuntimeModule } from 'webpack';\nimport { createRemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const RemoteWebpackRequireRuntimeModule =\n createRemoteWebpackRequireRuntimeModule(compiler.webpack);\n\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(\n this.appName,\n ) as unknown as RuntimeModule,\n );\n });\n },\n );\n }\n}\n","import { relative } from 'node:path';\nimport type { NormalModule, Compiler, RuntimeModule } from 'webpack';\nimport { createModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nconst cwd = process.cwd();\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(\n compiler.webpack,\n );\n\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id && (normalModule.resource || normalModule.request)) {\n moduleMap[\n relative(\n cwd,\n normalModule.resource || normalModule.request,\n )\n ] = id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n if (normalModule.resource || normalModule.request) {\n moduleMap[\n relative(cwd, normalModule.resource || normalModule.request)\n ] = id;\n }\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(\n this.appName,\n moduleMap,\n ) as unknown as RuntimeModule,\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","export function createModuleIdEmbedRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n };\n}\n","import type { Compiler } from 'webpack';\n\nexport class ConditionalExecPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const { Compilation, sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__ && globalThis.__DISABLE_WEBPACK_EXEC__[\"${this.appName}\"]) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import type { Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const { sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[^\\\\]]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n throw new Error(\\`Remote component loading error: \"\\${bundle}\"\\`);\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(new URL(url, globalThis.__remote_bundle_url__?.[\"${this.appName}\"] ?? location.origin).href, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,SAAS,QAAAA,OAAM,YAAAC,iBAAgB;AAClD,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,OAAO,qBAAqB;AAC5B,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAC7B,OAAO,gCAAgC;;;ACNvC,SAAS,YAAY;;;ACAd,SAAS,wCAAwC,SAErD;AACD,SAAO,MAAM,0CAA0C,QAAQ,cAAc;AAAA,IAG3E,YAAY,SAAiB;AAC3B,YAAM,wBAAwB;AAC9B,WAAK,UAAU;AAAA,IACjB;AAAA,IAEA,WAA0B;AACxB,aAAO,+HAA+H,KAAK;AAAA,IAC7I;AAAA,EACF;AACF;;;ACZO,IAAM,6BAAN,MAAiC;AAAA,EAGtC,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAAoB;AACxB,UAAM,oCACJ,wCAAwC,SAAS,OAAO;AAE1D,aAAS,MAAM,gBAAgB;AAAA,MAC7B;AAAA,MACA,CAAC,gBAAgB;AACf,oBAAY,MAAM,yBACf,IAAI,qBAAqB,EACzB,IAAI,8BAA8B,CAAC,UAAU;AAC5C,sBAAY;AAAA,YACV;AAAA,YACA,IAAI;AAAA,cACF,KAAK;AAAA,YACP;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACL;AAAA,IACF;AAAA,EACF;AACF;;;AC9BA,SAAS,gBAAgB;;;ACAlB,SAAS,iCAAiC,SAE9C;AACD,SAAO,MAAM,mCAAmC,QAAQ,cAAc;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I,CAAC;AAAA,IACpC;AAAA,EACF;AAEA,UAAQ,IAAI,+BAA+B;AAE3C,MAAI,QAAQ,IAAI,WAAW;AACzB,QACE,CAAE,aAA2B,UAAU;AAAA,MACrC,WAAW;AAAA,QACT,cAAc;AAAA,UACZ,GAAG;AAAA,QACL;AAAA,MACF;AAAA,MACA,UAAU;AAAA,QACR,cAAc;AAAA,UACZ,8BAA8B;AAAA,QAChC;AAAA,MACF;AAAA,IACF,CAAC,EAAE,SACH;AAEA,cAAQ;AAAA,QACN;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AACA,eAAW,YAAY;AAAA,MACrB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,WAAW;AAAA,QACzB,GAAG;AAAA,MACL;AAAA,IACF;AACA,eAAW,WAAW;AAAA,MACpB,GAAG,WAAW;AAAA,MACd,cAAc;AAAA,QACZ,GAAG,WAAW,UAAU;AAAA,QACxB,4CAA4C;AAAA,MAC9C;AAAA,IACF;AACA,oBAAgB;AAChB,WAAO;AAAA,EACT;AAGA,SAAO,UAAiB,YAAY;AAAA,IAClC,KAAK,EAAE,MAAM,UAAU;AAAA,IACvB;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["join","relative","join","relative"]}
1
+ {"version":3,"sources":["../../src/next/config/index.ts","../../src/next/config/webpack/index.ts","../../src/next/config/webpack/plugins/remote-webpack-require-runtime-module.ts","../../src/next/config/webpack/plugins/remote-webpack-require.ts","../../src/next/config/webpack/plugins/module-id-embed.ts","../../src/next/config/webpack/plugins/module-id-embed-runtime-module.ts","../../src/next/config/webpack/plugins/conditional-exec.ts","../../src/next/config/webpack/plugins/patch-require.ts"],"sourcesContent":["import { basename, dirname, join, relative } from 'node:path';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport enhancedResolve from 'enhanced-resolve';\nimport { findUpSync } from 'find-up';\nimport type { NextConfig } from 'next';\nimport { configSchema } from 'next/dist/server/config-schema.js';\nimport TsConfigPathsWebpackPlugin from 'tsconfig-paths-webpack-plugin';\nimport { transform as webpackTransform } from './webpack';\n\ninterface ZodSchema {\n safeParse: (data: unknown) => { success: boolean };\n}\n\ninterface WithRemoteComponentsOptions {\n /**\n * An array of package names that should be shared between the host and remote components.\n * This is useful for ensuring that both the host and remote components use the same version\n * of shared libraries.\n *\n * Essential packages are included by default: `react`, `react-dom`, `next/navigation`, `next/link`, `next/form`, `next/image`, and `next/script`.\n */\n shared?: string[];\n}\n\n/**\n * This function configures Next.js to support Remote Components.\n * You need to also use the `withMicrofrontends` function to extend your Next.js configuration.\n *\n * @param nextConfig - The Next.js configuration object.\n * @param options - Optional configuration for remote components.\n * @returns The modified Next.js configuration object with remote components support.\n *\n * @example\n *\n * ```js\n * import { withMicrofrontends } from '@vercel/microfrontends/next/config';\n * import { withRemoteComponents } from 'remote-components/next/config';\n *\n * const nextConfig = {\n * // your Next.js configuration\n * };\n *\n * export default withRemoteComponents(\n * withMicrofrontends(nextConfig),\n * {\n * shared: ['some-package', 'another-package'],\n * },\n * );\n * ```\n */\nexport function withRemoteComponents(\n nextConfig: NextConfig,\n options?: WithRemoteComponentsOptions,\n) {\n const virtualRemoteComponentAppSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/app-remote.tsx',\n );\n const virtualRemoteComponentPagesSharedRemote = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/pages-remote.tsx',\n );\n const virtualRemoteComponentConfigWrapper = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/config-wrapper.ts',\n );\n const virtualRemoteComponentAppSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/app-host.tsx',\n );\n const virtualRemoteComponentPagesSharedHost = join(\n process.cwd(),\n nextConfig.distDir ?? '.next',\n 'remote-components/shared/pages-host.tsx',\n );\n\n const appShared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/navigation',\n 'next/dist/client/components/navigation',\n 'next/link',\n 'next/dist/client/app-dir/link',\n 'next/form',\n 'next/dist/client/app-dir/form',\n 'next/image',\n 'next/dist/client/image-component',\n 'next/dist/api/image',\n 'next/script',\n 'next/dist/client/script',\n 'next/dist/build/polyfills/process',\n ],\n ...(options?.shared ?? []),\n ]);\n const pagesShared = new Set([\n ...[\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n 'next/router',\n 'next/link',\n 'next/image',\n 'next/script',\n 'next/form',\n ],\n ...(options?.shared ?? []),\n ]);\n\n const vendorShared: Record<string, string> = {\n react: `'/react/index.js'`,\n 'react/jsx-dev-runtime': `'/react/jsx-dev-runtime.js'`,\n 'react/jsx-runtime': `'/react/jsx-runtime.js'`,\n 'react-dom': `'/react-dom/index.js'`,\n };\n\n // resolve using enhanced-resolve\n // named import does not work with enhanced-resolve when using cjs\n // eslint-disable-next-line import/no-named-as-default-member\n const resolve = enhancedResolve.create.sync({\n conditionNames: ['browser', 'import', 'module', 'require'],\n ...(existsSync(join(process.cwd(), 'tsconfig.json'))\n ? {\n extensions: ['.js', '.jsx', '.ts', '.tsx'],\n plugins: [\n new TsConfigPathsWebpackPlugin({\n configFile: join(process.cwd(), 'tsconfig.json'),\n }) as unknown as enhancedResolve.Plugin,\n ],\n }\n : {}),\n });\n\n const generateSharedRemote = (sharedRemote: Set<string>) =>\n `'use client';\\nmodule.exports = { shared: { ${Array.from(sharedRemote)\n .reduce<string[]>((acc, curr) => {\n let path;\n try {\n path = resolve(process.cwd(), curr);\n if (path) {\n path = relative(process.cwd(), path).replace(\n /^(?<relative>\\.\\.\\/)+/,\n '',\n );\n }\n } catch {\n // noop\n // if module resolution using enhanced-resolve fails, fallback to require.resolve called in the shared/remote file\n }\n acc.push(\n `[${vendorShared[curr] ?? (path ? `'${path}'` : `require.resolve('${curr}')`)}]: '${curr}',`,\n );\n acc.push(\n `['__remote_shared_module_${curr}']: () => import('${curr}'),`,\n );\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n const generateSharedHost = (sharedHost: Set<string>) =>\n `'use client';\\nmodule.exports = { shared: { ${Array.from(sharedHost)\n .reduce<string[]>((acc, curr) => {\n acc.push(`['${curr}']: () => import('${curr}'),`);\n return acc;\n }, [])\n .join('\\n')} } };\\n`;\n\n const appSharedRemote = generateSharedRemote(appShared);\n const pagesSharedRemote = generateSharedRemote(pagesShared);\n\n const appSharedHost = generateSharedHost(appShared);\n const pagesSharedHost = generateSharedHost(pagesShared);\n\n const emitSharedFiles = () => {\n mkdirSync(dirname(virtualRemoteComponentAppSharedRemote), {\n recursive: true,\n });\n\n writeFileSync(\n virtualRemoteComponentAppSharedRemote,\n appSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentPagesSharedRemote,\n pagesSharedRemote,\n 'utf-8',\n );\n writeFileSync(\n virtualRemoteComponentConfigWrapper,\n '// withRemoteComponents enabled',\n 'utf-8',\n );\n writeFileSync(virtualRemoteComponentAppSharedHost, appSharedHost, 'utf-8');\n writeFileSync(\n virtualRemoteComponentPagesSharedHost,\n pagesSharedHost,\n 'utf-8',\n );\n };\n\n nextConfig.transpilePackages = [\n ...(nextConfig.transpilePackages ?? []),\n 'remote-components/next',\n 'remote-components/next/remote',\n 'remote-components/next/host',\n 'remote-components/next/host/pages-router',\n 'remote-components/next/host/client',\n 'remote-components/shared/remote/app',\n 'remote-components/shared/remote/pages',\n 'remote-components/shared/host/app',\n 'remote-components/shared/host/pages',\n ];\n\n const alias = {\n 'remote-components/shared/remote/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedRemote,\n )}`,\n 'remote-components/shared/remote/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedRemote,\n )}`,\n 'remote-components/shared/remote/wrapper': `./${relative(\n process.cwd(),\n virtualRemoteComponentConfigWrapper,\n )}`,\n 'remote-components/shared/host/app': `./${relative(\n process.cwd(),\n virtualRemoteComponentAppSharedHost,\n )}`,\n 'remote-components/shared/host/pages': `./${relative(\n process.cwd(),\n virtualRemoteComponentPagesSharedHost,\n )}`,\n };\n\n let projectId =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\n if (!projectId) {\n try {\n const projectPath = findUpSync('.vercel/project.json', {\n cwd: process.cwd(),\n });\n if (projectPath) {\n projectId = (\n JSON.parse(readFileSync(projectPath, 'utf8')) as { projectId: string }\n ).projectId;\n }\n } catch {\n // fallback to env‑var above\n }\n }\n\n if (!projectId) {\n const packageJsonPath = findUpSync('package.json', {\n cwd: process.cwd(),\n });\n if (packageJsonPath) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as {\n name?: string;\n };\n projectId = packageJson.name || basename(process.cwd());\n } else {\n projectId = basename(process.cwd());\n }\n }\n\n process.env.REMOTE_COMPONENTS_PROJECT_ID = projectId;\n\n if (process.env.TURBOPACK) {\n if (\n !(configSchema as ZodSchema).safeParse({\n turbopack: {\n resolveAlias: {\n ...alias,\n },\n },\n compiler: {\n defineServer: {\n REMOTE_COMPONENTS_PROJECT_ID: projectId,\n },\n },\n }).success\n ) {\n // eslint-disable-next-line no-console\n console.error(\n 'You need to use a Next.js version which supports the `turbopack` and `compiler.defineServer` configuration for Turbopack support with Remote Components.',\n );\n process.exit(1);\n }\n nextConfig.turbopack = {\n ...nextConfig.turbopack,\n resolveAlias: {\n ...nextConfig.turbopack?.resolveAlias,\n ...alias,\n },\n };\n nextConfig.compiler = {\n ...nextConfig.compiler,\n defineServer: {\n ...nextConfig.compiler?.defineServer,\n 'process.env.REMOTE_COMPONENTS_PROJECT_ID': projectId,\n },\n };\n emitSharedFiles();\n return nextConfig;\n }\n\n // apply the webpack transform\n return webpackTransform(nextConfig, {\n app: { name: projectId },\n alias,\n emitSharedFiles,\n });\n}\n","import { join } from 'node:path';\nimport type { NextConfig } from 'next';\nimport type { WebpackOptionsNormalized } from 'webpack';\nimport { RemoteWebpackRequirePlugin } from './plugins/remote-webpack-require';\nimport { ModuleIdEmbedPlugin } from './plugins/module-id-embed';\nimport { ConditionalExecPlugin } from './plugins/conditional-exec';\nimport { PatchRequirePlugin } from './plugins/patch-require';\n\nexport function transform(\n nextConfig: NextConfig,\n {\n app,\n alias = {},\n emitSharedFiles = () => {\n // no-op by default\n },\n }: {\n app: { name: string };\n alias?: Record<string, string>;\n emitSharedFiles?: () => void;\n },\n) {\n const webpackConfig = nextConfig.webpack;\n\n nextConfig.webpack = (\n baseConfig: WebpackOptionsNormalized,\n webpackContext,\n ) => {\n // execute the client config first, otherwise their config may accidentally\n // overwrite our required config - leading to unexpected errors.\n const config = (\n typeof webpackConfig === 'function'\n ? (webpackConfig(baseConfig, webpackContext) ?? baseConfig)\n : baseConfig\n ) as WebpackOptionsNormalized;\n\n // remote component specific plugins\n config.plugins.push(\n new RemoteWebpackRequirePlugin(app.name),\n new ModuleIdEmbedPlugin(app.name),\n new ConditionalExecPlugin(app.name),\n new PatchRequirePlugin(app.name),\n );\n if (!webpackContext.isServer) {\n // change the chunk loading global to avoid conflicts with other remote components\n config.output.chunkLoadingGlobal = `__remote_chunk_loading_global_${app.name}__`;\n }\n\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve.alias,\n ...Object.fromEntries(\n Object.entries(alias).map(([key, value]) => [\n key,\n join(process.cwd(), value),\n ]),\n ),\n },\n };\n\n emitSharedFiles();\n return config;\n };\n\n return nextConfig;\n}\n","export function createRemoteWebpackRequireRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class RemoteWebpackRequireRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n\n constructor(appName: string) {\n super('remote-webpack-require');\n this.appName = appName;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_require__ = globalThis.__remote_webpack_require__ || {}; globalThis.__remote_webpack_require__[\"${this.appName}\"] = __webpack_require__;`;\n }\n };\n}\n","import type { Compiler, RuntimeModule } from 'webpack';\nimport { createRemoteWebpackRequireRuntimeModule } from './remote-webpack-require-runtime-module';\n\nexport class RemoteWebpackRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const RemoteWebpackRequireRuntimeModule =\n createRemoteWebpackRequireRuntimeModule(compiler.webpack);\n\n compiler.hooks.thisCompilation.tap(\n 'RemoteWebpackRequirePlugin',\n (compilation) => {\n compilation.hooks.runtimeRequirementInTree\n .for('__webpack_require__')\n .tap('RemoteWebpackRequirePlugin', (chunk) => {\n compilation.addRuntimeModule(\n chunk,\n new RemoteWebpackRequireRuntimeModule(\n this.appName,\n ) as unknown as RuntimeModule,\n );\n });\n },\n );\n }\n}\n","import { relative } from 'node:path';\nimport type { NormalModule, Compiler, RuntimeModule } from 'webpack';\nimport { createModuleIdEmbedRuntimeModule } from './module-id-embed-runtime-module';\n\nconst cwd = process.cwd();\n\nexport class ModuleIdEmbedPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const ModuleIdEmbedRuntimeModule = createModuleIdEmbedRuntimeModule(\n compiler.webpack,\n );\n\n compiler.hooks.thisCompilation.tap('ModuleIdEmbedPlugin', (compilation) => {\n const moduleMap = {} as Record<string, string | number>;\n\n compilation.hooks.runtimeRequirementInTree\n .for(compiler.webpack.RuntimeGlobals.require)\n .tap('ModuleIdEmbedPlugin', (chunk, set) => {\n for (const [key, entry] of compilation.entrypoints) {\n for (const entryChunk of entry.chunks) {\n if (key.includes('nextjs-pages-remote')) {\n for (const mod of compilation.chunkGraph.getChunkModulesIterable(\n entryChunk,\n )) {\n const id = compilation.chunkGraph.getModuleId(mod);\n const normalModule = mod as NormalModule;\n if (id && (normalModule.resource || normalModule.request)) {\n moduleMap[\n relative(\n cwd,\n normalModule.resource || normalModule.request,\n )\n ] = id;\n }\n }\n }\n }\n }\n for (const mod of compilation.modules) {\n const id = compilation.chunkGraph.getModuleId(mod);\n if (id && mod.layer?.endsWith('browser')) {\n const normalModule = mod as NormalModule;\n if (normalModule.resource || normalModule.request) {\n moduleMap[\n relative(cwd, normalModule.resource || normalModule.request)\n ] = id;\n }\n }\n }\n\n if (Object.keys(moduleMap).length > 0) {\n compilation.addRuntimeModule(\n chunk,\n new ModuleIdEmbedRuntimeModule(\n this.appName,\n moduleMap,\n ) as unknown as RuntimeModule,\n );\n\n set.add(compiler.webpack.RuntimeGlobals.require);\n }\n });\n });\n }\n}\n","export function createModuleIdEmbedRuntimeModule(webpack: {\n RuntimeModule: new (name: string, stage?: number) => object;\n}) {\n return class ModuleIdEmbedRuntimeModule extends webpack.RuntimeModule {\n appName: string;\n moduleMap: Record<string | number, unknown>;\n\n constructor(appName: string, moduleMap: Record<string | number, unknown>) {\n super('remote-webpack-module-id-embed');\n this.appName = appName;\n this.moduleMap = moduleMap;\n }\n\n generate(): null | string {\n return `globalThis.__remote_webpack_module_map__ = globalThis.__remote_webpack_module_map__ || {}; globalThis.__remote_webpack_module_map__[\"${this.appName}\"] = ${JSON.stringify(this.moduleMap)};`;\n }\n };\n}\n","import type { Compiler } from 'webpack';\n\nexport class ConditionalExecPlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const { Compilation, sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap(\n 'ConditionalExecPlugin',\n (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'ConditionalExecPlugin',\n stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n (assets) => {\n for (const [name, source] of Object.entries(assets)) {\n if (name.endsWith('.js')) {\n const patchedSource = source\n .source()\n .toString()\n .replace(\n `var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))`,\n `var __webpack_exec__ = (moduleId) => { if (globalThis.__DISABLE_WEBPACK_EXEC__ && globalThis.__DISABLE_WEBPACK_EXEC__[\"${this.appName}\"]) return; return __webpack_require__(__webpack_require__.s = moduleId); }`,\n );\n compilation.updateAsset(\n name,\n new sources.RawSource(patchedSource),\n );\n }\n }\n },\n );\n },\n );\n }\n}\n","import type { Compiler } from 'webpack';\n\n// This plugin patches the webpack require function to support loading remote components in Next.js\nexport class PatchRequirePlugin {\n appName: string;\n\n constructor(appName: string) {\n this.appName = appName;\n }\n\n apply(compiler: Compiler) {\n const { sources } = compiler.webpack;\n\n compiler.hooks.thisCompilation.tap('PatchRequirePlugin', (compilation) => {\n compilation.mainTemplate.hooks.requireExtensions.tap(\n 'PatchRequirePlugin',\n (source) => {\n return new sources.ConcatSource(\n source,\n `const __webpack_require_orig__ = __webpack_require__;\nconst REMOTE_RE = /\\\\[(?<bundle>[^\\\\]]+)\\\\] (?<id>.*)/;\n__webpack_require__ = function __remote_webpack_require__(remoteId) {\n const match = REMOTE_RE.exec(remoteId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_orig__(remoteId);\n }\n if (typeof self.__remote_webpack_require__?.[bundle] !== 'function') {\n const error = new Error(\\`Remote Components are not available in \"\\${bundle}\". Did you forget to wrap the Next.js config with \\\\\\`withRemoteComponents\\\\\\` on both host and remote?\\`);\n error.name = 'RemoteComponentsError';\n error.code = 'REMOTE_COMPONENTS_ERROR';\n throw error;\n }\n return self.__remote_webpack_require__[bundle](self.__remote_webpack_require__[bundle].type === 'turbopack' ? remoteId : id);\n};\nObject.assign(__webpack_require__, __webpack_require_orig__);\nconst __webpack_require_l__ = __webpack_require__.l;\n__webpack_require__.l = function __remote_webpack_require_l__(url, done, key, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_l__(new URL(url, globalThis.__remote_bundle_url__?.[\"${this.appName}\"] ?? location.origin).href, done, key, chunkId);\n }\n return done();\n};\nconst __webpack_require_o__ = __webpack_require__.o;\n__webpack_require__.o = function __remote_webpack_require_o__(installedChunks, chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_o__(installedChunks, chunkId);\n }\n return installedChunks[chunkId] = 0;\n};\nconst __webpack_require_e__ = __webpack_require__.e;\n__webpack_require__.e = function __remote_webpack_require_e__(chunkId) {\n const match = REMOTE_RE.exec(chunkId);\n const bundle = match?.groups?.bundle;\n const id = match?.groups?.id;\n if (!(id && bundle)) {\n return __webpack_require_e__(chunkId);\n }\n return Promise.resolve([]);\n};`,\n )\n .source()\n .toString();\n },\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,UAAU,SAAS,QAAAA,OAAM,YAAAC,iBAAgB;AAClD,SAAS,YAAY,WAAW,cAAc,qBAAqB;AACnE,OAAO,qBAAqB;AAC5B,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB;AAC7B,OAAO,gCAAgC;;;ACNvC,SAAS,YAAY;;;ACAd,SAAS,wCAAwC,SAErD;AACD,SAAO,MAAM,0CAA0C,QAAQ,cAAc;AAAA,IAG3E,YAAY,SAAiB;AAC3B,YAAM,wBAAwB;AAC9B,WAAK,UAAU;AAAA,IACjB;AAAA,IAEA,WAA0B;AACxB,aAAO,+HAA+H,KAAK;AAAA,IAC7I;AAAA,EACF;AACF;;;ACZO,IAAM,6BAAN,MAAiC;AAAA,EAGtC,YAAY,SAAiB;AAC3B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAAoB;AACxB,UAAM,oCACJ,wCAAwC,SAAS,OAAO;AAE1D,aAAS,MAAM,gBAAgB;AAAA,MAC7B;AAAA,MACA,CAAC,gBAAgB;AACf,oBAAY,MAAM,yBACf,IAAI,qBAAqB,EACzB,IAAI,8BAA8B,CAAC,UAAU;AAC5C,sBAAY;AAAA,YACV;AAAA,YACA,IAAI;AAAA,cACF,KAAK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le, resolve) {
74
74
  }
75
75
  }
76
76
 
77
+ // src/shared/error.ts
78
+ var RemoteComponentsError = class extends Error {
79
+ constructor(message, options) {
80
+ super(message, options);
81
+ this.code = "REMOTE_COMPONENTS_ERROR";
82
+ this.name = "RemoteComponentsError";
83
+ }
84
+ };
85
+ function multipleRemoteComponentsError(url) {
86
+ return new Error(
87
+ `Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
88
+ );
89
+ }
90
+ function failedToFetchRemoteComponentError(url, error) {
91
+ return new RemoteComponentsError(
92
+ `Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
93
+ { cause: error instanceof Error ? error : new Error(String(error)) }
94
+ );
95
+ }
96
+
77
97
  // src/shared/webpack/next-client-pages-loader.ts
78
98
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
79
99
  const self = globalThis;
@@ -112,8 +132,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
112
132
  (key) => key.includes("/next/dist/client/page-loader.js")
113
133
  ) ?? ""] ?? -1;
114
134
  if (!(componentLoaderChunk && appLoaderChunk)) {
115
- throw new Error(
116
- `Next.js client pages loader not found in bundle "${bundle}"`
135
+ throw new RemoteComponentsError(
136
+ `Next.js client pages loader not found in bundle "${bundle}".`
117
137
  );
118
138
  }
119
139
  const __NEXT_P_ORIGINAL = self.__NEXT_P;
@@ -337,11 +357,11 @@ async function handleTurbopackChunk(code, bundle, url) {
337
357
  scriptResolve(void 0);
338
358
  script.remove();
339
359
  };
340
- script.onerror = (error) => {
360
+ script.onerror = () => {
341
361
  URL.revokeObjectURL(scriptUrl);
342
362
  scriptReject(
343
- new Error(
344
- `Failed to load script: ${error instanceof Error ? error.message : String(error)}`
363
+ new RemoteComponentsError(
364
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
345
365
  )
346
366
  );
347
367
  script.remove();
@@ -383,11 +403,11 @@ function createModuleRequire(runtime) {
383
403
  if (bundle && moduleId) {
384
404
  return handleTurbopackModule(bundle, moduleId, id);
385
405
  }
386
- throw new Error(`Module ${id} not found`);
406
+ throw new Error(`Module "${id}" not found.`);
387
407
  } catch (requireError) {
388
408
  if (typeof self.__original_webpack_require__ !== "function") {
389
- throw new Error(
390
- `Module ${id} not found in remote component bundle ${bundle}`,
409
+ throw new RemoteComponentsError(
410
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
391
411
  {
392
412
  cause: requireError instanceof Error ? requireError : void 0
393
413
  }
@@ -396,8 +416,8 @@ function createModuleRequire(runtime) {
396
416
  try {
397
417
  return self.__original_webpack_require__(id);
398
418
  } catch (originalError) {
399
- throw new Error(
400
- `Module ${id} not found in remote component bundle ${bundle}`,
419
+ throw new RemoteComponentsError(
420
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
401
421
  { cause: originalError instanceof Error ? originalError : void 0 }
402
422
  );
403
423
  }
@@ -527,7 +547,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
527
547
  }
528
548
  const exports = {};
529
549
  const moduleExports = { exports };
530
- const exportNames = /* @__PURE__ */ new Set();
531
550
  if (!self.__remote_components_turbopack_modules__) {
532
551
  self.__remote_components_turbopack_modules__ = {};
533
552
  }
@@ -563,31 +582,53 @@ function handleTurbopackModule(bundle, moduleId, id) {
563
582
  };
564
583
  }
565
584
  },
566
- // define exports
567
- s(m) {
568
- let mod = m;
569
- if (Array.isArray(m)) {
570
- mod = {};
571
- const keys = [];
572
- for (const current of m) {
573
- if (typeof current === "string") {
574
- keys.push(current);
575
- } else if (typeof current === "function") {
576
- while (keys.length > 0) {
577
- const key = keys.shift();
578
- if (key) {
579
- mod[key] = current;
580
- }
585
+ // esm
586
+ s(bindings, esmId) {
587
+ let mod = exports;
588
+ if (typeof esmId === "string" || typeof esmId === "number") {
589
+ if (!self.__remote_components_turbopack_modules__) {
590
+ self.__remote_components_turbopack_modules__ = {};
591
+ }
592
+ if (!self.__remote_components_turbopack_modules__[bundle]) {
593
+ self.__remote_components_turbopack_modules__[bundle] = {};
594
+ }
595
+ if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
596
+ self.__remote_components_turbopack_modules__[bundle][esmId] = {};
597
+ }
598
+ mod = self.__remote_components_turbopack_modules__[bundle][esmId];
599
+ }
600
+ Object.defineProperty(mod, "__esModule", { value: true });
601
+ if (Array.isArray(bindings)) {
602
+ let i = 0;
603
+ while (i < bindings.length) {
604
+ const propName = bindings[i++];
605
+ const tagOrFunc = bindings[i++];
606
+ if (typeof tagOrFunc === "number") {
607
+ Object.defineProperty(mod, propName, {
608
+ value: bindings[i++],
609
+ enumerable: true,
610
+ writable: false
611
+ });
612
+ } else {
613
+ const getterFn = tagOrFunc;
614
+ if (typeof bindings[i] === "function") {
615
+ const setterFn = bindings[i++];
616
+ Object.defineProperty(mod, propName, {
617
+ get: getterFn,
618
+ set: setterFn,
619
+ enumerable: true
620
+ });
621
+ } else {
622
+ Object.defineProperty(mod, propName, {
623
+ get: getterFn,
624
+ enumerable: true
625
+ });
581
626
  }
582
627
  }
583
628
  }
584
629
  }
585
- for (const [key, value] of Object.entries(mod)) {
586
- exports[key] = value;
587
- exportNames.add(key);
588
- }
589
630
  },
590
- // import ESM
631
+ // import
591
632
  i(importId) {
592
633
  let mod;
593
634
  if (typeof importId === "string") {
@@ -611,7 +652,10 @@ function handleTurbopackModule(bundle, moduleId, id) {
611
652
  } else {
612
653
  mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
613
654
  }
614
- if (!("default" in mod) && mod.toString() !== "[object Module]") {
655
+ if (typeof mod !== "object") {
656
+ mod = { default: mod };
657
+ } else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
658
+ mod.toString() !== "[object Module]") {
615
659
  try {
616
660
  mod.default = mod;
617
661
  } catch {
@@ -630,7 +674,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
630
674
  return self.__webpack_require__?.(`[${bundle}] ${vid}`);
631
675
  });
632
676
  } else {
633
- exports.default = value;
677
+ moduleExports.exports = value;
634
678
  }
635
679
  },
636
680
  // async module initializer
@@ -664,7 +708,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
664
708
  return self.__webpack_chunk_load__?.(bundleUrl, bundle);
665
709
  }
666
710
  }
667
- throw new Error(`Failed to load chunk ${url} for module ${id}`);
711
+ throw new Error(
712
+ `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
713
+ );
668
714
  },
669
715
  // global
670
716
  g: self.__remote_components_turbopack_global__[bundle],
@@ -674,11 +720,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
674
720
  moduleExports,
675
721
  exports
676
722
  );
677
- for (const name of exportNames) {
678
- if (typeof exports[name] === "function") {
679
- exports[name] = exports[name]();
680
- }
681
- }
682
723
  if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
683
724
  self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
684
725
  }
@@ -701,8 +742,8 @@ async function loadScripts(scripts) {
701
742
  };
702
743
  newScript.onerror = () => {
703
744
  reject(
704
- new Error(
705
- `Failed to load script ${script.src} for remote component`
745
+ new RemoteComponentsError(
746
+ `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
706
747
  )
707
748
  );
708
749
  };
@@ -850,7 +891,10 @@ async function loadRemoteComponent({
850
891
  } catch (error) {
851
892
  return {
852
893
  component: null,
853
- error: error instanceof Error ? error : new Error(String(error))
894
+ error: new RemoteComponentsError(
895
+ `Failed to load remote component "${name}".`,
896
+ { cause: error instanceof Error ? error : new Error(String(error)) }
897
+ )
854
898
  };
855
899
  }
856
900
  }
@@ -866,7 +910,9 @@ async function loadRSCComponent(rscName, data) {
866
910
  createFromReadableStream = _createFromReadableStream;
867
911
  }
868
912
  if (typeof createFromReadableStream !== "function") {
869
- throw new Error("Failed to import react-server-dom-webpack");
913
+ throw new RemoteComponentsError(
914
+ 'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
915
+ );
870
916
  }
871
917
  const stream = createRSCStream(rscName, data);
872
918
  const component = createFromReadableStream(stream);
@@ -875,8 +921,8 @@ async function loadRSCComponent(rscName, data) {
875
921
  function loadNextPagesComponent(bundle, route, nextData, name, container) {
876
922
  const { Component, App } = nextClientPagesLoader(bundle, route, container);
877
923
  if (!Component) {
878
- throw new Error(
879
- `Remote component ${name} is trying to load the component for route ${route} but it is not available.`
924
+ throw new RemoteComponentsError(
925
+ `Remote Component "${name}" is trying to load the component for route "${route}" but it is not available.`
880
926
  );
881
927
  }
882
928
  const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
@@ -1340,7 +1386,6 @@ function RemoteComponent({
1340
1386
  }
1341
1387
  }, [src]);
1342
1388
  (0, import_react.useEffect)(() => {
1343
- let mounted = true;
1344
1389
  if (src && src !== prevSrcRef.current) {
1345
1390
  prevSrcRef.current = src;
1346
1391
  (0, import_react.startTransition)(async () => {
@@ -1356,9 +1401,31 @@ function RemoteComponent({
1356
1401
  };
1357
1402
  const res = await fetch(url, fetchInit);
1358
1403
  if (!res.ok) {
1359
- throw new Error(
1360
- `Failed to fetch remote component "${name}": ${res.status}`
1361
- );
1404
+ let error = failedToFetchRemoteComponentError(url.href, {
1405
+ cause: new Error(`${res.status} ${res.statusText}`)
1406
+ });
1407
+ try {
1408
+ const body = await res.text();
1409
+ const parser2 = new DOMParser();
1410
+ const doc2 = parser2.parseFromString(body, "text/html");
1411
+ const errorTemplate = doc2.querySelector(
1412
+ "template[data-next-error-message]"
1413
+ );
1414
+ const errorMessage = errorTemplate?.getAttribute(
1415
+ "data-next-error-message"
1416
+ );
1417
+ const errorStack = errorTemplate?.getAttribute(
1418
+ "data-next-error-stack"
1419
+ );
1420
+ if (errorMessage) {
1421
+ error = new RemoteComponentsError(errorMessage);
1422
+ if (errorStack) {
1423
+ error.stack = errorStack;
1424
+ }
1425
+ }
1426
+ } catch {
1427
+ }
1428
+ throw error;
1362
1429
  }
1363
1430
  const remoteHtml = await res.text();
1364
1431
  htmlRef.current = remoteHtml;
@@ -1366,6 +1433,9 @@ function RemoteComponent({
1366
1433
  }
1367
1434
  const parser = new DOMParser();
1368
1435
  const doc = parser.parseFromString(html, "text/html");
1436
+ if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`)) {
1437
+ throw multipleRemoteComponentsError(url.href);
1438
+ }
1369
1439
  const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
1370
1440
  doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
1371
1441
  doc.querySelector("div#__next");
@@ -1387,7 +1457,9 @@ function RemoteComponent({
1387
1457
  const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
1388
1458
  remoteSharedEl?.remove();
1389
1459
  if (!component || !(rsc || nextData)) {
1390
- throw new Error(`Failed to find component with id "${remoteName}"`);
1460
+ throw new RemoteComponentsError(
1461
+ `Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
1462
+ );
1391
1463
  }
1392
1464
  applyOriginToNodes(doc, url);
1393
1465
  const links = Array.from(
@@ -1479,6 +1551,15 @@ function RemoteComponent({
1479
1551
  };
1480
1552
  componentHydrationHtml.current = Array.from(doc.querySelectorAll("link,style")).map((link) => link.outerHTML).join("") + component.innerHTML;
1481
1553
  const userShared = await shared;
1554
+ if ("__remote_components_missing_shared__" in userShared) {
1555
+ userShared.__remote_components_missing_shared__().catch((e) => {
1556
+ throw e;
1557
+ });
1558
+ } else if ("__remote_components_missing_shared__" in remoteShared) {
1559
+ throw new RemoteComponentsError(
1560
+ remoteShared.__remote_components_missing_shared__
1561
+ );
1562
+ }
1482
1563
  const result = await loadRemoteComponent({
1483
1564
  url: new URL(url, location.origin),
1484
1565
  name: remoteName,
@@ -1523,15 +1604,10 @@ function RemoteComponent({
1523
1604
  setRemoteComponent(result.component);
1524
1605
  }
1525
1606
  } catch (error) {
1526
- if (mounted) {
1527
- setRemoteComponent(error);
1528
- }
1607
+ setRemoteComponent(error);
1529
1608
  }
1530
1609
  });
1531
1610
  }
1532
- return () => {
1533
- mounted = false;
1534
- };
1535
1611
  }, [
1536
1612
  url,
1537
1613
  src,
@@ -1710,7 +1786,7 @@ var routerImpl = async () => {
1710
1786
  var import_jsx_runtime4 = require("react/jsx-runtime");
1711
1787
  async function tryImportShared() {
1712
1788
  try {
1713
- const { shared } = await import("@remote-components/shared/host/app");
1789
+ const { shared } = await import("remote-components/shared/host/app");
1714
1790
  return shared;
1715
1791
  } catch {
1716
1792
  return {};