vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Shared modules send error

Open AndreiSoroka opened this issue 2 years ago • 3 comments

Versions

  • originjs: 1.1.6
  • node: v16.14.0

Steps to reproduce

npm init vue@latest
image and default example https://www.npmjs.com/package/@originjs/vite-plugin-federation

my config vite.config.ts

import { fileURLToPath, URL } from "url";
import federation from "@originjs/vite-plugin-federation";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 8003,
  },
  plugins: [
    vue(),
    federation({
      name: "ff_payment_service",
      filename: "remoteEntry.js",
      exposes: {
        "./AboutView.vue": "./src/views/AboutView.vue",
      },
      shared: ["vue"], // <- error
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});

What is Expected?

build without problem

What is actually happening?

image
error during build:
Error: Transform failed with 1 error:
assets/__federation_expose_AboutViewVue.js:3:74: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
    at failureErrorWithLog (./temp/node_modules/esbuild/lib/main.js:1605:15)
    at ./temp/node_modules/esbuild/lib/main.js:1394:29
    at ./temp/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (./temp/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (./temp/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (node:events:520:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

AndreiSoroka avatar Jun 30 '22 23:06 AndreiSoroka

Federation uses a Top-level await, which is supported by the following browsers. Change your config build.target to next or a similar value. image https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#browser_compatibility

ygj6 avatar Jul 02 '22 09:07 ygj6

@ygj6 A lot of thanks

  build: {
    target: ["chrome89", "edge89", "firefox89", "safari15"],
  },

and

  build: {
    target: "esnext",
  },

I think need to add it to README.md https://github.com/originjs/vite-plugin-federation for other people and close this issue

AndreiSoroka avatar Jul 02 '22 18:07 AndreiSoroka

You may want to see this comment https://github.com/originjs/vite-plugin-federation/pull/213#issuecomment-1180018123

MarkusJLechner avatar Jul 13 '22 07:07 MarkusJLechner