InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

TypeError: Cannot read properties of undefined (reading 'length')

Open Bortnyak opened this issue 3 years ago • 1 comments

Sometimes I face this issue in different environments (ubuntu 20.04 and macOS Monterey): 'TypeError: Cannot read properties of undefined (reading 'length')'

Did anybody face the same issue?

Environment

  • Node v16.16.0 (tried 14/18 and got the same)
  • yarn v1.22.19
  • macOS Monterey
  • "inversify": "^5.0.1",
  • "inversify-express-utils": "6.3.2",

Stack trace

TypeError: Cannot read properties of undefined (reading 'length')
    at pathtoRegexp (/Users/volodymyr/Documents/repos/observe-api/node_modules/path-to-regexp/index.js:63:49)
    at new Layer (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/node_modules/express/lib/router/layer.js:45:17)
    at Function.use (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/node_modules/express/lib/router/index.js:464:17)
    at Function.<anonymous> (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/node_modules/express/lib/application.js:220:21)
    at Array.forEach (<anonymous>)
    at Function.use (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/node_modules/express/lib/application.js:217:7)
    at InversifyExpressServer.registerControllers (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/lib/server.js:161:19)
    at InversifyExpressServer.build (/Users/volodymyr/Documents/repos/observe-api/node_modules/inversify-express-utils/lib/server.js:121:14)
    at Object.<anonymous> (/Users/volodymyr/Documents/repos/observe-api/dist/App.js:68:18)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
error Command failed with exit code 1.

Bortnyak avatar Jul 28 '22 13:07 Bortnyak

Figured out that this issue happens when do not specify the rootPath param. Here is my inversify server config

let server = new InversifyExpressServer(
  container,
  null,
  { rootPath: config.apiRootPath },
  null,
  null
);

Here I specified the rootPath param but forgot to set it in my config.

Bortnyak avatar Jul 29 '22 22:07 Bortnyak