错误 TS2339:表达“应用程序”类型上不存在属性“使用”

问题描述 投票:0回答:3

最近我们旧编写的微服务之一(Nodejs V10 + Typescript V7.0.1)开始抛出以下错误:

return new TSError(diagnosticText, diagnosticCodes)
TSError: ⨯ Unable to compile TypeScript:
src/app.ts(31,14): error TS2339: Property 'listen' does not exist on type 'Application'.
src/app.ts(48,14): error TS2339: Property 'use' does not exist on type 'Application'.
src/app.ts(49,14): error TS2339: Property 'use' does not exist on type 'Application'.
src/app.ts(50,14): error TS2339: Property 'set' does not exist on type 'Application'.
src/app.ts(51,14): error TS2339: Property 'set' does not exist on type 'Application'.
src/app.ts(52,14): error TS2339: Property 'use' does not exist on type 'Application'.

代码环境

我们在 docker-compose 中运行代码,以维护旧的 Nodejs 和 TypeScript 版本、Dockerfile 内容

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm", "run", "start" ]

相同的代码可以在本地系统上运行,但不能在开发服务器上运行。 google 没有找到相关信息,请您指点一下可能是什么原因。

提前谢谢您。

node.js typescript express node-modules
3个回答
10
投票

DT 不再支持 TS 4.0。

尝试使用以前版本的软件包

  • @types/express (4.17.13)
  • @types/express-serve-static-core (4.17.30)

10
投票

经过大量的研发,我们了解到 ts-nodetypescript npms 需要更新。以下命令解决问题。

npm i ts-node --save-dev && npm i typescript --save-dev

0
投票

如果您已完成上述所有操作但仍然遇到错误,则可能需要检查您的 node_modules 目录是否已损坏或过时。在这种情况下,您可以尝试删除node_modules目录并重新安装依赖项(npm install或yarn install)。这通常有助于解决任何与打字相关的问题。

© www.soinside.com 2019 - 2024. All rights reserved.