Next.js Discord

Discord Forum

When is transpilePackages necessary?

Unanswered
Alligator mississippiensis posted this in #help-forum
Open in Discord
Avatar
Alligator mississippiensisOP
I'm setting up a new turborepo monorepo with some nextjs 14 apps.

I have apps/web and apps/docs as test applications and they both use a packages/ui component library. When I run a dev server, I see no difference using transpilePackages: ['@repo/ui'] or not. I guess I'm not understanding what it's doing and why/when I need it. Wouldn't those internal packages be included anyway in dev/builds because I'm importing their code?

4 Replies

Avatar
Jesse677
If you look here.
https://nextjs.org/docs/app/api-reference/next-config-js/transpilePackages
It states that Next JS will automatically transpile and bundle packages from monorepos.
The only time I had to use transpilePackages is when I was using the crypto package. https://github.com/brix/crypto-js/issues/415#issuecomment-1837938710
Avatar
Alligator mississippiensisOP
I did read that, but I guess I'm not clear on why it's needed. I think it's because I'm importing files from another internal package that would not be "available" if I built this project because unlike node_modules/depedencies, I'd have to tell nextjs to bundle them
when I run dev mode, they're available because my whole monorepo is avail, but if I were to deploy the nextjs app, those internal modules wouldn't be included by default?
Avatar
Jesse677
yeah, that's kinda what happened to me, I could use cyrpto in dev mode but when I deployed it didn't work and I had to add the transpilePackagaes, so I think it's only for things which don't automatically get transpiled by next.