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

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

Open
Vladislav-Lukyanuk opened this issue Jan 31, 2025 · 1 comment

Comments

@Vladislav-Lukyanuk
Copy link

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 ?

@gioboa
Copy link
Collaborator

gioboa commented Feb 1, 2025

Hi @Vladislav-Lukyanuk
No it's not working, I'm sorry.
Is cjs mandatory for you?

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

2 participants