Module parse failed: Cannot use 'import.meta' outside a module
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
- [X] Read the docs.
- [X] Read the common issues list.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Module federation issue and not a framework-specific issue.
- [X] The provided reproduction is a minimal reproducible example of the bug.
@ScriptedAlchemy I think we've had this problem before
@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.
@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
Stale issue message