Skip to content

Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather. #248

Open
@Vladislav-Lukyanuk

Description

@Vladislav-Lukyanuk

Hi! If I try to build a cjs code using

build: {
    outDir: './dist',
    modulePreload: false,
    minify: false,
    cssCodeSplit: true,
    assetsDir: '',

    rollupOptions: {
      output: {
        format: 'commonjs',
      }
    }
  },

I got the error Module format "cjs" does not support top-level await. Use the "es" or "system" output formats rather. from node_modules/__mf__virtual/xxx__loadShare__react__loadShare__

;() => import("__mf__virtual/xxx__prebuild__react__prebuild__.js").catch(() => {});
// dev uses dynamic import to separate chunks

const {loadShare} = require("@module-federation/runtime")
const {initPromise} = require("__mf__virtual/xxx__mf_v__runtimeInit__mf_v__.js")
const res = initPromise.then(_ => loadShare("react", {
customShareInfo: {shareConfig:{
  singleton: true,
  strictVersion: false,
  requiredVersion: "17.0.2"
}}}))
const exportModule = await res.then(factory => factory())
module.exports = exportModule

It seems to me comes from runtime code generation by library. Can I build __mf__virtual using cjs ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions