Closed cxwcfea closed 7 years ago
This is happening because opts
is actually the Awilix cradle
which is a Proxy. When console.log
attempts to log the proxy, it tries to look up Symbol(util.inspect.custom)
which isn't registered. This then tries to throw a descriptive error, but by doing that it attempts to convert the symbol to a string.
I'm not sure how to work around this quite yet; reserving inspect
as a registration and disallowing symbols might break some people's uses.
@cxwcfea I have published Awilix v2.9.0 which addresses this issue. When console.logging the opts
(which is the cradle), you should not see [AwilixContainer.cradle]
instead.
Thanks for reporting!
@talyssonoc you can close this. 😄
@cxwcfea @jeffijoe sorry for the long delay on that! I'm glad it got resolved, gonna aim to update awilix-express soon.
I am using awilix-express 0.11.0, awilix 2.8.4 in a Typescript project . I have a class:
export default class SmsController { smsService: ISms; logger: any;
constructor(opts) { console.log(opts); this.smsService = opts.smsService; this.logger = opts.logger; }
sendCaptcha(req: express.Request, res: express.Response): void { this.logger.debug(
hello sendCaptcha api ${process.pid}
); res.json({ msg: 'ok' }); } }and in a express router file, I use it like this:
import * as express from 'express'; import Ctrl from '../controllers/sms'; import { SmsService } from '../services/sms'; const { makeClassInvoker } = require('awilix-express');
const router = express.Router();
const api = makeClassInvoker(Ctrl);
router.get('/captcha', api('sendCaptcha'));
export default router;
please note the console.log(opts) in SmsController's constructor, it will trigger an exception which tells: TypeError: Cannot convert a Symbol value to a string If I comment this line, everything is ok, I think this is a bug in makeClassInvoker. Thanks