NextJS SyntaxError: Unexpected token 'export' on node_modules

I am trying to test/switch a Vite+React repo to NextJS+React.
After making the basic changes i got this error:

export { generateUtils } from "./generate-utils";

SyntaxError: Unexpected token 'export'

I tried changing tsconfig from esnext to es5 but there were no changes in the error message.
The error is thrown in the react-router-typing and I can't make changes to the node_module.
The import location looks like so:

import { defineRoutes, asBrowserRouter, AsRouteConfig, generateUtils } from 'react-router-typing'


export const { pagePath, pageMatch } = generateUtils<RouteConfig>()


  • Add the library to thetranspilePackages in next.config.js

    /** @type {import('next').NextConfig} */
    const nextConfig = {
        reactStrictMode: true,
        transpilePackages: [
    export default nextConfig

    Found the answer here.