-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Barrel optimizer (optimizeImports) breaks RSC Components bundler: Could not find the module in the React Client Manifest #54967
Comments
Possibily similar issue as in #55029 |
@shuding is this something you already ran into when building the "optimizePackageImports" process? Or are mixed client- & server components not a usecase here? I was also not able to workaround this by splitting the imports in a file by server- & client components unfortunately. |
I'll take a look at this today 🙏 |
Hi @shuding are there any updates or temporary fixes for this issue? |
👀 |
Dirty workaround is to hack Next.js so the You can do this with the patch-package module. Patch: patches/next+13.5.2.patch diff --git a/node_modules/next/dist/server/config.js b/node_modules/next/dist/server/config.js
index efd81cf..10b1d4a 100644
--- a/node_modules/next/dist/server/config.js
+++ b/node_modules/next/dist/server/config.js
@@ -507,7 +507,7 @@ function assignDefaults(dir, userConfig, silent) {
if (!result.experimental) {
result.experimental = {};
}
- result.experimental.optimizePackageImports = [
+ result.experimental.optimizePackageImports = [] || [
...new Set([
...userProvidedOptimizePackageImports,
"lucide-react",
After this, everything started working again. Related: #55566, #55609. Note: of course this is an unsupported workaround that may also break at any time. |
Apologize for the delay! I just found the root cause to this and will open a PR to fix it today. Meanwhile what @bartlangelaan mentioned can be a temporary workaround. |
The barrel optimization loader creates a virtual module to re-export from the original file, which causes the situation that now there are 2 modules with the same resource but only one of them is the actual code. When the code contains `"use client"`, the Flight plugin has to collect its `buildInfo` and generate the manifest and client entry module. However, we currently deduplicate module by resource in the traversal logic to avoid unnecessary loops. To make it work together with the virtual barrel module, we'll need to prefix the resource path to make it different from the original module. Closes #54967. Closes #55609. Closes #55566.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue or a replay of the bug
https://github.com/florianliebig/next-error-optimize-package-imports
To Reproduce
Checkout example repo
pnpm i && pnpm build
Steps to create error:
Current vs. Expected behavior
I would expect both Server & client components to be optimized properly from #54695
import { ClientComponent, ServerComponent } from '@shared/components';
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:17:35 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8112 Binaries: Node: 18.16.0 npm: 9.6.7 Yarn: 1.22.19 pnpm: 8.6.2 Relevant Packages: next: 13.5.3-canary.0 eslint-config-next: 13.4.19 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
App Router, SWC transpilation
Additional context
No response
The text was updated successfully, but these errors were encountered: