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:
Set up a Next.js project with TypeScript and install next-intl.
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
},
});
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:
import { defineRouting } from "next-intl";
Is there a recent change in the next-int
l 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.
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