originjs / vite-plugin-federation

Module Federation for vite & rollup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL

tomorrow285 opened this issue · comments

Versions

  • vite-plugin-federation: 1.3.5
  • vite: 4.5.3

Reproduction

After I run npm run build, I got this error.

This is my vite.config.ts:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import vitePluginRequire from 'vite-plugin-require';
import ViteRequireContext from '@originjs/vite-plugin-require-context';
import federation from '@originjs/vite-plugin-federation';
import topLevelAwait from 'vite-plugin-top-level-await';
import { viteCommonjs, esbuildCommonjs } from '@originjs/vite-plugin-commonjs';


export default defineConfig(({ mode }) => {
    return {
        base: '/',
        plugins: [
            react(),
            vitePluginRequire(),
            ViteRequireContext(),
            federation({
                name: 'bohrium',
                remotes: {
                    dpMol: {
                        external: 'https://cdn.xxxx/remoteEntry.js',
                        externalType: 'url',
                        format: 'var',
                    },
                },
                filename: 'remoteEntry.[contenthash:8].js',
                exposes: {
                    './A': '../src/shared/hooks/a',
                    './B': '../src/shared/components/b',
                },
                shared: ['react', 'react-dom'],
            }),
            topLevelAwait({
                promiseExportName: '__tla',
                promiseImportName: i => `__tla_${i}`,
            }),
            viteCommonjs(),
        ],
        optimizeDeps: {
            esbuildOptions: {
                target: ['es2015', 'safari11'],
                plugins: [esbuildCommonjs()],
            },
            exclude: ['jquery'],
        },
        build: {
            target: ['es2015', 'safari11'],
            outDir: './build',
            rollupOptions: {
                external: ['react', 'react-dom', 'jquery'],
                output: {
                    globals: {
                        react: 'React',
                        'react-dom': 'ReactDOM',
                        jquery: ['jQuery', '$'],
                    },
                },
            },
            sourcemap: true,
        },

    };
});

This is the error log:

Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
    at __federation_fn_import-b9cca9f6.js:1:5743

What is actually happening?

The error occurs in new URL(xxx, K.url) because K is an empty object.

This is the code in __federation_fn_import-b9cca9f6.js, the complete document is in the attachment:

const K = {};
const q = {
    react: {
        get: ()=>()=>I(new URL("__federation_shared_react-2fa0e958.js",K.url).href),
        import: !0
    },
[__federation_fn_import-b9cca9f6.js.zip](https://github.com/originjs/vite-plugin-federation/files/14902568/__federation_fn_import-b9cca9f6.js.zip)

    "react-dom": {
        get: ()=>()=>I(new URL("__federation_shared_react-dom-661945d7.js",K.url).href),
        import: !0
    }
}

你这个问题解决了么?

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Have you solved this problem?

commented

我也遇到同样的问题,该如何解决?
image