我正在尝试将我的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中获取的地方时,我可以看到它从vs.代码库中的lib.es6.d.ts读取它,所以我猜这个文件在服务器上不可用但我不知道如何将其包含在服务器中?
编辑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"
]
}
答案 0 :(得分:2)
您必须在应用根目录(客户端或服务器端)的某处导入reflect-metadata
。请参阅Inversify documentation。
答案 1 :(得分:0)
这在很大程度上取决于您构建应用的方式。它是码头,s2i还是定制。了解应用程序的构建方式,您必须确保其自己的构建过程将安装此依赖项,或者构建所基于的映像包含所有必需的deps。