0

I'm trying to deploy my node.js project to the openshift server, My project runs fine on my local machine but when deployed on the server it complains as follows

/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)

On VS code when I track the file and try to see where does it get from the Reflect I can see that it reads it from lib.es6.d.ts in vs code libraries so I guess that file isn't available on the server but I don't know how can I include it in the server?

Edit 1: I'm not using docker and my package.js is as follow:

{
  "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"
  }
}

and my tsconfig.json is:

{
    "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"
    ]
}
user4092086
  • 986
  • 3
  • 12
  • 24

2 Answers2

2

You must import reflect-metadata somewhere at your app root, either client or server-side. See Inversify documentation.

Jules Sam. Randolph
  • 3,610
  • 2
  • 31
  • 50
  • Thanks! Yeah I was importing it in some other places, placed it only on app bootstrap file and the error is gone, although I was wonder why it wasn't complaining when I was on my local machine. – user4092086 Dec 06 '17 at 03:13
0

That depends a lot on how you build your app. Is it a docker, s2i or custom. Knowing how your app is built, you have to make sure that either its own build process will install this dependency or that the image your build is based on contains all the required deps.

Radek 'Goblin' Pieczonka
  • 21,554
  • 7
  • 52
  • 48
  • I'm not using docker and my app is build from package.json, Edited the question and included the package.json and config.ts – user4092086 Dec 05 '17 at 17:27