当我的项目部署到服务器时没有定义反射

Reflect is not defined when my project is deployed to the server

我正在尝试将我的 node.js 项目部署到 openshift 服务器, 我的项目在我的本地机器上运行良好,但是当部署在服务器上时,它会抱怨如下

/opt/app-root/src/node_modules/inversify/lib/annotation/decorator_utils.js:22
    if (Reflect.hasOwnMetadata(metadataKey, annotationTarget) === true) {
        ^

ReferenceError: Reflect is not defined
    at _tagParameterOrProperty (/opt/app-root/src/node_modules/inversify/lib/annotation/decorator_utils.js:22:9)
    at Object.tagProperty (/opt/app-root/src/node_modules/inversify/lib/annotation/decorator_utils.js:12:5)
    at /opt/app-root/src/node_modules/inversify/lib/annotation/inject.js:13:31
    at __decorate (/opt/app-root/src/node_modules/inversify-express-utils/lib/base_http_controller.js:5:110)
    at /opt/app-root/src/node_modules/inversify-express-utils/lib/base_http_controller.js:17:5
    at Object.<anonymous> (/opt/app-root/src/node_modules/inversify-express-utils/lib/base_http_controller.js:25:2)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

在 VS 代码上,当我跟踪文件并尝试查看它从 Reflect 获取的位置时,我可以看到它是从 lib.es6.d.ts 中读取它的,在 vs 代码库中,所以我猜该文件在服务器上不可用但我不知道如何将它包含在服务器中?

编辑 1: 我没有使用 docker,我的 package.js 如下:

{
  "name": "mmm",
  "version": "1.0.0",
  "description": "",
  "main": "build/bootstrap.js",
  "scripts": {
    "compile": "tsc --declaration && node build/bootstrap.js",
    "dev": "nodemon -e ts  --exec \"npm run compile\"",       
    "start": "nodemon -e ts  --exec \"npm run compile\"",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "author": "mmmm",
  "license": "ISC",
  "dependencies": {
    "@types/body-parser": "^1.16.5",
    "@types/express": "^4.0.39",
    "@types/node": "^8.0.44",
    "bluebird": "^3.5.1",
    "body-parser": "^1.18.2",
    "commander": "^2.12.2",
    "deep-diff": "^0.3.8",
    "express": "^4.16.2",
    "fs-finder": "^1.8.1",
    "inversify": "^4.5.2",
    "inversify-express-utils": "^4.0.1",
    "keypress": "^0.2.1",
    "knex": "^0.13.0",
    "mysql": "^2.15.0",
    "pg": "^7.3.0",
    "reflect-metadata": "^0.1.10",
    "request": "^2.83.0",
    "tape": "^4.8.0",
    "typeorm": "^0.1.1"
  },
  "devDependencies": {
    "nodemon": "^1.12.1",
    "typescript": "^2.6.2"
  }
}

我的 tsconfig.json 是:

{
    "compilerOptions": {
       "target": "es6",
        "lib": ["es6", "dom"],
        "types": ["reflect-metadata"],
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "outDir": "build",
        "declarationDir": "declaration",
        "watch": false
    },
    "exclude": [
        "node_modules",
        "build",
        "declaration"
    ]
}

这在很大程度上取决于您构建应用程序的方式。它是 docker、s2i 还是自定义。了解您的应用程序是如何构建的,您必须确保它自己的构建过程将安装此依赖项,或者您构建所基于的映像包含所有必需的依赖项。

您必须将 reflect-metadata 导入应用程序根目录的某个位置,无论是客户端还是服务器端。参见 Inversify documentation