首页 > 解决方案 > Elastic Beanstalk “错误 TS2688:找不到‘节点’的类型定义文件。”

问题描述

我正在尝试将应用程序部署到弹性 beantalk 的 NodeJs 平台(10.15.3),但随着它的构建(节点命令是npm start --production),我在日志中看到以下错误:

npm run build
app@1.0.0 build /var/app/current
tsc -p .
error TS2688: Cannot find type definition file for 'node'.

我的 package.json 如下(它包括 @type/node:10.14):

{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "main": "dist/app.js",
  "scripts": {
    "build": "tsc -p .",
    "prestart": "npm run build",
    "watch": "tsc -w -p .",
    "start": "node .",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@types/morgan": "^1.7.35",
    "@types/node": "^10.14",
    "aws-sdk": "^2.411.0",
    ...
  },
  "devDependencies": {
    "@types/express": "^4.16.1"
  }
}

标签: node.jsamazon-web-servicesamazon-elastic-beanstalk

解决方案


您应该将类​​型添加到您的tsconfig.json

 {
   "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "outDir": "dist-api",
      "sourceMap": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "types": ["node"]
   },
   "include": [
      "src/**/*.ts"
   ],
   "exclude": [
      "node_modules"
   ]
}

推荐阅读