Skip to content

fix: Example code in README doesn't work #790

Closed
@petertorelli

Description

@petertorelli

Description

Following instructions for Express on README.md code fails with: TypeError: Reflect.getMetadata is not a function

Minimal code-snippet showcasing the problem
Simply type the first example in the README of this repo (UserController.ts & app.ts).

Expected behavior

Expecting the example to work.

Actual behavior

Fails to start:

% yarn build (runs tsc on the two .ts files)
% yarn start
:
:
/Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata/ParamMetadata.js:36
            const ParamTypes = Reflect.getMetadata('design:paramtypes', args.object, args.method);
                                       ^

TypeError: Reflect.getMetadata is not a function
    at new ParamMetadata (/Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata/ParamMetadata.js:36:40)
    at /Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata-builder/MetadataBuilder.js:111:31
    at Array.map (<anonymous>)
    at MetadataBuilder.createParams (/Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata-builder/MetadataBuilder.js:111:14)
    at /Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata-builder/MetadataBuilder.js:98:34
    at Array.map (<anonymous>)
    at MetadataBuilder.createActions (/Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata-builder/MetadataBuilder.js:95:34)
    at /Users/ptorelli/study/routing-controller-study/node_modules/routing-controllers/cjs/metadata-builder/MetadataBuilder.js:75:39
    at Array.map (<anonymous>)
: 
: 

My package.json:

% cat package.json 
{
  "name": "routing-controller-study",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc",
    "start": "node ./dist/app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "class-transformer": "0.3.1",
    "class-validator": "0.12.2",
    "express": "^4.17.1",
    "multer": "^1.4.3",
    "reflect-metadata": "^0.1.13",
    "routing-controllers": "^0.9.0"
  },
  "devDependencies": {
    "@types/body-parser": "^1.19.1",
    "@types/express": "^4.17.13",
    "@types/multer": "^1.4.7",
    "typescript": "^4.4.4"
  }
}

And tsconfig.json:

{
  "exclude": [ "node_modules", "dist" ],
  "include": [ "src/**/*" ],
  "compilerOptions": {
    "target": "es2019",
    "experimentalDecorators": true, 
    "emitDecoratorMetadata": true, 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "outDir": "./dist", 
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions