jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 61 forks source link

Unable to create object "XXXX" required by: unknown #63

Closed darshit7 closed 6 years ago

darshit7 commented 7 years ago

I don't know why I am getting this error. Below is my code

  1. custom_logger.js
    
    exports = module.exports = function() {
    let mylog = new Promise((resolve, reject=>{
    console.log("Initializing promise function.");
    resolve("Worked fine");
    }));
    return mylog;
    }

exports['@singleton'] = true;


2. app.js

var IoC = require('electrolyte'); var mylog = IoC.create('custom_logger'); mylog.then(function(msg) { / do something with the result / }).catch(function(err) { console.log(err); });


This error which I got while running `node app.js`

Error: Unable to create object "custom_logger" required by: unknown at /home/darshitp/Documents/nodejs/di/node_modules/electrolyte/lib/container.js:146:18 at Container._loadSpec (/home/darshitp/Documents/nodejs/di/node_modules/electrolyte/lib/container.js:216:10) at Container. (/home/darshitp/Documents/nodejs/di/node_modules/electrolyte/lib/container.js:144:12) at tryCallTwo (/home/darshitp/Documents/nodejs/di/node_modules/promise/lib/core.js:45:5) at doResolve (/home/darshitp/Documents/nodejs/di/node_modules/promise/lib/core.js:200:13) at new Promise (/home/darshitp/Documents/nodejs/di/node_modules/promise/lib/core.js:66:3) at Container._create (/home/darshitp/Documents/nodejs/di/node_modules/electrolyte/lib/container.js:132:10) at Container.create (/home/darshitp/Documents/nodejs/di/node_modules/electrolyte/lib/container.js:120:15) at Object. (/home/darshitp/Documents/nodejs/di/index.js:2:17) at Module._compile (module.js:571:32)

wingedfox commented 7 years ago

Try to use the master branch, @jaredhanson just merged PR with more informative errors. It seems that you have not defined a loader:

ioc.use(ioc.dir('src'));