-
Notifications
You must be signed in to change notification settings - Fork 28k
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
transpilePackages doesn't tree-shake barrel export in turborepo #55943
Comments
Same here. Moreover, it doesn't tree shake even with "ordinary-non-barrel" exports. // lib/client.tsx
'use client'
export function ClientComponent() {...} // lib/server.tsx
export function ServerComponent() {...} // lib/index.tsx
export { ClientComponent } from './client'
export { ServerComponent } from './server' Then, in the app: // app/page.tsx
import { ServerComponent } from "./lib";
export default function Page() {
return <ServerComponent />;
}
|
@mehulkar could we get some input from the Next.js team on this? Looks like it's a pretty big issue, making some internal libs completely unusable. Thanks in advance 😄 |
I can confirm this issue still exists on Next v13.5.5 |
This comment has been minimized.
This comment has been minimized.
this exists on 14.01 as well |
Although I believe I've seen @shuding recommending against it for now on Twitter, I've had success using the experimental /** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ["ui"],
experimental: {
optimizePackageImports: ["ui"]
}
}
module.exports = nextConfig If your The number of modules for some pages decreased by over 10k for us |
|
This partially worked for me but I ended up having some components that still imported server specific functions. I ended up going this (long) route I found on the turborepo discord server. Server components header, main-layout and footer are packaged then properly separated. I could referenced the "src" folder directly rather than creating an exports but I had a lot of other code nested in that folder and this approach just seemed cleaner.
Used like this:
|
We're facing what could very well be the same issue on next During development, no matter if turbo is enabled or not, the We've spent the entire day removing all our barrel exports, updating imports and testing but we can't seem to fix this problem any way. We'd really appreciate some input as to how we're supposed to debug these issues and how to reduce the 4gb memory usage while in development. |
If you have something like a UI library with many, many components, what do you replace barrel files with? How do you organize exports? I feel like I'm missing something obvious. |
Link to the code that reproduces this issue
https://github.com/raphaelbadia/barrel-exports-transpile-module-not-treeshaking
To Reproduce
yarn build
in the root repositoryCurrent vs. Expected behavior
Following the steps from the previous section, I expected the build output to be very light for the / (home page), something like :
λ / 137 B 79.4 kB
.However I instead saw :
λ / 13.7 kB 92.9 kB
Three tabs opened, in the
client.html
one, I clicked the left drawer, choseapp/page
as the chunk to explore and saw packages that aren't used:Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
SWC transpilation
Additional context
I was trying to understand why my website is so heavy, and decided to create a new project from scratch. I realised that the problem appears as soon as I add a library to the UI package.
The text was updated successfully, but these errors were encountered: