Tuesday, 23 May 2017

While executing mocha tests, Getting error "reflect-metadata shim is required when using class decorators"

Written one mocha test case with chai in Typescript and followed the article http://brianflove.com/2016/11/11/typescript-2-express-mongoose-mocha-chai/ to install all dependencies.

While I am running the test cases with "npm test", I am getting below error

C:\J\MEAN\MSDN-App\node_modules\@angular\core\bundles\core.umd.js:335 throw 'reflect-metadata shim is required when using class decorators'; ^ reflect-metadata shim is required when using class decorators npm ERR! Test failed. See above for more details.

The package.json is:

{
  "name": "test-app",
  "version": "1.0.0",
  "description": "test description",
  "main": "server.js",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "test": "mocha -r ts-node/register test/**/*.ts",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.0.1",
    "@angular/compiler": "^2.0.1",
    "@angular/core": "^2.0.1",
    "@angular/forms": "^2.0.1",
    "@angular/http": "^2.0.1",
    "@angular/platform-browser": "^2.0.1",
    "@angular/platform-browser-dynamic": "^2.0.1",
    "@angular/router": "^3.4.10",
    "@angular/upgrade": "^2.0.1",
    "@covalent/core": "^1.0.0-beta.3-2",
    "@ngrx/store": "^2.0.1",
    "@types/node": "7.0.7",
    "@types/underscore": "^1.8.0",
    "angular-in-memory-web-api": "^0.1.1",
    "body-parser": "^1.17.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "ejs": "^2.5.6",
    "express": "^4.15.2",
    "mongojs": "^2.4.0",
    "node-sspi": "^0.1.14",
    "nodemailer": "^4.0.1",
    "nodemailer-smtp-transport": "^2.7.4",
    "properties-reader": "0.0.15",
    "reflect-metadata": "^0.1.10",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "ts-node": "^3.0.4",
    "underscore": "^1.8.3",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "@types/chai": "^3.5.2",
    "@types/core-js": "0.9.35",
    "@types/mocha": "^2.2.41",
    "chai": "^3.5.0",
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "mocha": "^3.4.1",
    "reflect-metadata": "^0.1.10",
    "ts-node": "^3.0.4",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  }
}

And tsconfig.json is:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
        "exclude": [
                "node_modules",
                "node_modules/@types",
                "bower_components",
                "typings"
        ]
}

Please help to resolve the error.



via Ram's

No comments:

Post a Comment