reactjstypescriptnext.jsi18nextnext-intl

TypeScript Error: defineRouting expects 0 arguments but got 1 during npm run build


I'm encountering a TypeScript error when running npm run build in my Next.js project that uses next-intl. Interestingly, the error does not occur when I run npm run dev; everything works as expected in the development environment.

./i18n/routing.ts:4:38
Type error: Expected 0 arguments, but got 1.

  2 | import { defineRouting } from "next-intl/routing";
  3 |
  4 | export const routing = defineRouting({
    |                                      ^
  5 |   locales: ["en", "es"],
  6 |   defaultLocale: "en",
  7 |   pathnames: {

Steps to Reproduce:

  1. Set up a Next.js project with TypeScript and install next-intl.

  2. Create an i18n/routing.ts file with the following content:

    import { defineRouting } from "next-intl/routing";
    
    export const routing = defineRouting({
      locales: ["en", "es"],
      defaultLocale: "en",
      pathnames: {
        // Custom route configurations
      },
    });
    
  3. Run npm run build to build the project for production.

This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [{ "name": "next" }],
    "types": ["@testing-library/jest-dom", "jest", "node"],
    "paths": { "@/*": ["./*"] },
    "typeRoots": ["./types", "./node_modules/@types"]
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "global.d.ts",
    "jest.config.js"
  ],
  "exclude": ["node_modules"]
}

Environment:

Expected Behavior:

The project should build successfully without any TypeScript errors, just as it does during development with npm run dev.

Actual Behavior:

The build process fails with the TypeScript error mentioned above, indicating that defineRouting expects 0 arguments but received 1.

What I've Tried:

Is there a recent change in the next-intl library affecting the defineRouting function? Should it now be called without arguments? How can I resolve this TypeScript error during the build process?

The fact that npm run dev works without issues suggests that the problem arises during the production build's stricter type checking.


Solution

  • This solves the problem using "typescript": "^5.6.3" or downgrade the @types/next-intl next-intl routing.ts giving TS2554: Expected 0 arguments, but got 1