最近我们旧编写的微服务之一(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 没有找到相关信息,请您指点一下可能是什么原因。
提前谢谢您。
经过大量的研发,我们了解到 ts-node 和 typescript npms 需要更新。以下命令解决问题。
npm i ts-node --save-dev && npm i typescript --save-dev
如果您已完成上述所有操作但仍然遇到错误,则可能需要检查您的 node_modules 目录是否已损坏或过时。在这种情况下,您可以尝试删除node_modules目录并重新安装依赖项(npm install或yarn install)。这通常有助于解决任何与打字相关的问题。