martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Question - Why is this package still needed when Nextjs 12 supports ES Modules? #265

Closed jeremytenjo closed 2 years ago

jeremytenjo commented 2 years ago

Nextjs 12 supposedly supports ES Modules, why does it still fail when building a Nextjs app with NPM packages that are ES modules?

image

martpie commented 2 years ago

Because Next.js support for ES Modules is light, and does not support advanced usecases like importing CSS from node_modules, advanced monorepos setup, or applying your babel transformations to the packages you import from node_modules (a few random examples).

If you just plan on using ES Modules from npm, Next.js built-in support should serve you well :)

jeremytenjo commented 2 years ago

Thanks @martpie for the reason, makes sense👍

For people interested, the Nextjs team has an open RFC to fix this issue.

https://github.com/vercel/next.js/discussions/27953

martpie commented 2 years ago

I believe global css import has been solved a while ago from the Next.js team 🤔

From what I see in the comment, this doesn't include transpiling them via Babel though.