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

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

Open
tomorrow285 opened this issue Apr 8, 2024 · 7 comments

Comments

@tomorrow285
Copy link

tomorrow285 commented Apr 8, 2024

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
    }
}
@1511578084
Copy link

你这个问题解决了么?

@Issues-translate-bot
Copy link

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


Have you solved this problem?

@CS19940801
Copy link

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

@foreverstars
Copy link

foreverstars commented Aug 8, 2024

我也遇到同样的问题
1723110899864

@Issues-translate-bot
Copy link

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


I also encountered the same problem

@stonelove
Copy link

Image
好像是因为这个问题, 我把target: 'esnext'后就没问题了

@Issues-translate-bot
Copy link

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


Image
It seems that because of this problem, I changed target: 'esnext' and there was no problem.

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

No branches or pull requests

6 participants