簡體   English   中英

NextJS服務器文件中的Typescript錯誤

[英]Typescript error in server file for NextJS

我正在使用以下軟件包版本:

  • 下一個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"]
}

我收到以下Typescript錯誤:

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

我不明白這里發生了什么。 誰能解釋這個錯誤,為什么這個流行的軟件包的核心功能之一會拋出該錯誤? 我是否需要為某些缺少的內容手動擴展某些Next類型?

由於您的代碼實際上可與next v8.1.0(最新發布的版本)和@types/next next v8.0.0一起使用,但與next v8.1.1-canary.42一起使用時,可能意味着它們引入了一些不兼容的更改,從而使現有的.d.ts文件已過期。 @types/*軟件包是由獨立的志願者維護的,這些軟件包不會費心發布TypeScript類型定義,並且經常更新較晚,尤其是在我們談論某些預發布的版本時。

您可以考慮使用next (v8.1.0)的最新版本嗎?

或者,您可以嘗試了解版本之間的變化,並生成自己的.d.ts文件以供使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM