0

I'm using the following package versions:

  • next v8.1.1-canary.42
  • @types/next v8.0.5

server.js

import next from 'next';
const app = next({ dev: isDevelopment });

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": ["dom", "es2017"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext"
  },
  "exclude": ["node_modules"]
}

I get the following Typescript error:

Cannot invoke an expression whose type lacks a call signature. Type 'typeof import(".../node_modules/next/types/index")' has no compatible call signatures.

I can't understand what's going on here. Can anyone help explain this error and why one of the core functions for this popular package throws it? Do I need to manually extend some Next types for something that's missing?

1 Answer 1

2

Since your code actually works with next v8.1.0 (the latest released version) and @types/next v8.0.0, but breaks with next v8.1.1-canary.42, it might just mean that they introduced some incompatible changes that made the existing .d.ts files out of date. The @types/* packages are maintained by independent volunteers for those packages that don't bother publishing the TypeScript type definitions, and are often late to update, especially if we are talking about some pre-released version.

Can you consider using the latest version of next (v8.1.0)?

As an alternative, you might try to understand what changed between versions, and produce your own .d.ts files to use.

Sign up to request clarification or add additional context in comments.

1 Comment

You're right! I was getting ahead of the game because I say Typescript declarations had been added to the prerelease versions of NextJS and I thought this would be helpful as I'm adding Typescript to my NextJS project, but having reverted back to the current release, it's removed that error plus 3 others I had.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.