Assuming you've got a Next.js app that's already using TypeScript to render pages/components or handle API routes, but you also want to be able to run ad hoc build tasks written in TypeScript (perhaps pulling in type files used by the app)...
- Add these deps:
npm install -D @babel/core @babel/node
- Make sure your Next app has an explicit
.babelrc
file:
// Default Next.js .babelrc (it's OK if you also have extra stuff in it)
{
"presets": ["next/babel"],
"plugins": []