core icon indicating copy to clipboard operation
core copied to clipboard

Module parse failed: Cannot use 'import.meta' outside a module

Open bestseob93 opened this issue 1 year ago • 3 comments

Describe the bug

I am using the @module-federation/nextjs-mf(v8.3.16) in Next.js(v14.2.3). After adding the following code, I need to add module-federation/nextjs-mf to the transpilePackages in the Next.js config due to optional chaining. However, after adding it to transpilePackages, I encounter the following error in the CommonJS environment.

./.yarn/__virtual__/@module-federation-nextjs-mf-virtual-34f89ea0b4/0/cache/@module-federation-nextjs-mf-npm-8.3.16-24f98595be-5fa15c6859.zip/node_modules/@module-federation/nextjs-mf/dist/src/federation-noop.js
Module parse failed: Cannot use 'import.meta' outside a module (47:16)

Reproduction

i don't have one

Used Package Manager

yarn

System Info

System:
    OS: macOS 14.1.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 294.88 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    Yarn: 3.8.1 - ~/.nvm/versions/node/v18.17.0/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
    pnpm: 8.11.0 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
  Browsers:
    Chrome: 125.0.6422.112
    Safari: 17.1

Validations

bestseob93 avatar May 29 '24 10:05 bestseob93

@ScriptedAlchemy I think we've had this problem before

zhoushaw avatar May 31 '24 12:05 zhoushaw

@zhoushaw - this is different issue. They are opting into transpile the package which is causing react loader to be added back after i disabled it.

ScriptedAlchemy avatar Jun 02 '24 20:06 ScriptedAlchemy

@bestseob93 Do you know where exactly the issue is in my source? What file is crashing it? Where's the optional chaining that's crashing you. And is this server or browser build that breaks?

You cannot transpile the runtime again. Doing so next adds its hot loader which uses import meta. Which won't work in non esm source

ScriptedAlchemy avatar Jun 02 '24 20:06 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar Aug 02 '24 15:08 github-actions[bot]