简体   繁体   English

NextJS服务器文件中的Typescript错误

[英]Typescript error in server file for NextJS

I'm using the following package versions: 我正在使用以下软件包版本:

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

server.js server.js

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

tsconfig.json 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: 我收到以下Typescript错误:

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? 我是否需要为某些缺少的内容手动扩展某些Next类型?

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. 由于您的代码实际上可与next v8.1.0(最新发布的版本)和@types/next next v8.0.0一起使用,但与next v8.1.1-canary.42一起使用时,可能意味着它们引入了一些不兼容的更改,从而使现有的.d.ts文件已过期。 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. @types/*软件包是由独立的志愿者维护的,这些软件包不会费心发布TypeScript类型定义,并且经常更新较晚,尤其是在我们谈论某些预发布的版本时。

Can you consider using the latest version of next (v8.1.0)? 您可以考虑使用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. 或者,您可以尝试了解版本之间的变化,并生成自己的.d.ts文件以供使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM