Next.js + Transpile
Transpile untranspiled modules from
Makes it easy to have local libraries and keep a slick, manageable dev experience.
|Next.js version||Plugin version|
|Next.js 6 / 7||1.x|
npm install --save next-plugin-transpile-modules
yarn add next-plugin-transpile-modules
// next.config.jsconst withTM = ;moduleexports =;
note: please declare
withTM as your last plugin (the "most nested" one).
const withTypescript = ;const withTM = ;moduleexports =;
What is the difference with
- it is maintained,
@weco's seems dead
- it supports TypeScript
I have trouble making it work with Next.js 7
Next.js 7 introduced Webpack 4 and Babel 7, which changed a couple of things, especially for TypeScript and Flow plugins.
If you have a transpilation error when loading a page, check that your
babel.config.js is up to date and valid, you may have forgotten a preset there.
I have trouble with Yarn and hot reloading
If you add a local library (let's say with
yarn add ../some-shared-module), Yarn will copy those files by default, instead of symlinking them. So your changes to the initial folder won't be copied to your Next.js
You can go back to
npm, or use Yarn workspaces. See an example in the official Next.js repo.
I have trouble making it work with Lerna
Lerna's purpose is to publish different packages from a monorepo, it does not help for and do not intend to help local development with local modules.
This is not coming from me, but from Lerna's maintainer.
So you are probably using it wrong, and I advice you to use
npm or Yarn workspaces instead.