QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.26k stars 59 forks source link

pnpm build: "Type error: Expected 0 arguments, but got 1. " #198

Closed ofranquesa closed 11 months ago

ofranquesa commented 11 months ago

Describe the bug When trying to build the next.js app (pnpm build command), the process throws this error with exit status = 1.

To Reproduce Steps to reproduce the behavior:

  1. go to console
  2. run "pnpm build"
  3. wait for compilation
  4. build fails due to the "type error"

Expected behavior After checking the type declaration on your plugin, this error shouldn't happen since clearly the function allows arguments.

Screenshots

Captura de Pantalla 2023-09-27 a las 22 33 14

About (please complete the following information):

QuiiBz commented 11 months ago

Could you send your complete middleware.ts file or a reproduction link? I'm not able to reproduce the error in any project using next-international nor in the example: https://github.com/QuiiBz/next-international/tree/main/examples/next-app

ofranquesa commented 11 months ago

Thanks for your prompt reply!

By the end, I've end up changing the format from .ts -> .js and it worked out. Obviously I had to remove some little TS notation.

I've basically copied your middleware.ts from the documentation:

`// middleware.ts import { createI18nMiddleware } from 'next-international/middleware' import { NextRequest } from 'next/server'

const I18nMiddleware = createI18nMiddleware({ locales: ['en', 'de'], defaultLocale: 'de' })

export function middleware(request: NextRequest) { return I18nMiddleware(request) }

export const config = { matcher: ['/((?!api|static|.\..|_next|favicon.ico|robots.txt).*)'] }`

QuiiBz commented 11 months ago

This seems to be an issue with your TypeScript config, as we have the same middleware.ts file in this example and it's working fine: https://codesandbox.io/p/sandbox/jovial-paper-skkprk?file=%2Fmiddleware.ts

I'll close the issue but feel free to send a reproduction that can showcase the same error!

walterspieler commented 8 months ago

Hello here! Hope you're doing well!

I have the same error and switching the middlware file to js worked for me as well (thank you!) but it doesnt feel like the right way to do so .

For info here's my tsconfig

{
  "compilerOptions": {
    "removeComments": true,
    "preserveConstEnums": true,
    "alwaysStrict": true,
    "strictNullChecks": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "allowUnreachableCode": false,
    "noFallthroughCasesInSwitch": true,
    "outDir": "out",
    "declaration": true,
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "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,
    "paths": {
      "@/*": ["./src/*"],
      "@/public/*": ["./public/*"]
    },
    "plugins": [
      {
        "name": "next"
      }
    ]
  },
  "exclude": ["./out/**/*", "./node_modules/**/*"],
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    "app/middleware.js"
  ]
}

Thank you, Matt.

walterspieler commented 8 months ago

Ok, I could make the build work using the same next config you use. But it still doesnt feel right to ignorebuilderrors and ignoreDuringBuilds:

 /** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['next-international', 'international-types'],
  eslint: {
    ignoreDuringBuilds: true,
  },
  typescript: {
    ignoreBuildErrors: true,
  },
  // Uncomment to set base path
  // basePath: '/base',
  // Uncomment to use Static Export
  // output: 'export',
};

module.exports = nextConfig;
QuiiBz commented 8 months ago

Ok, I could make the build work using the same next config you use. But it still doesnt feel right to ignorebuilderrors and ignoreDuringBuilds:

We don't recommend at all to use eslint.ignoreDuringBuilds / typescript.ignoreBuildErrors, that depends on your project setup (in our case, we already run eslint & typescript in all the monorepo at once, so it's not needed to run it there too)