Inversifyjs: Getting "Cannot read property 'name' of undefined"

Created on 5 Feb 2017  路  7Comments  路  Source: inversify/InversifyJS

Expected Behavior

My requested instance gets made :)

Current Behavior

/app/node_modules/inversify/lib/planning/planner.js:106
            throw new Error(error.message);
                  ^
Error: Cannot read property 'name' of undefined
    at _createSubRequests (/app/node_modules/inversify/lib/planning/planner.js:106:19)
    at Object.plan (/app/node_modules/inversify/lib/planning/planner.js:125:5)
    at /app/node_modules/inversify/lib/container/container.js:205:37
    at Container._get (/app/node_modules/inversify/lib/container/container.js:198:44)
    at Container.get (/app/node_modules/inversify/lib/container/container.js:163:21)
    at /app/src/Command/anecdote-add-author.ts:25:28
    at /app/src/Command/anecdote-add-author.ts:4:17
    at Object.<anonymous> (/app/src/Command/anecdote-add-author.ts:10:3)
    at Module._compile (module.js:570:32)
    at Module.m._compile (/app/node_modules/ts-node/src/index.ts:406:23)

Possible Solution

It might be that error the feedback can be improved here if it's as a result of something I've done incorrectly.

Steps to Reproduce (for bugs)

You can see where I do my injections here: https://github.com/atrauzzi/anecdote-engine/blob/master/src/Engine/ConfigurationReader.ts#L27

The project is currently in a WIP state, but you should be able to get to the error with yarn/npm run add-author

Context

Injection in typescript without relying on annotations.

Ideally, I'd like to keep inversify's influence on my classes to a minimum.

Your Environment

My project is containerized, but I see no reason why you can't check it out and work with it using your own tooling setup :)

Stack trace

See above :)

Most helpful comment

Just for the record, I had this problem and it was caused by Typescript. I flushed the /ts-node folder and it worked then.

All 7 comments

Hi, I think the key point is:

without relying on annotations

When you don't use annotations you need to generate additional metadata. For example, constructor injections that use classes as types need to be manually annotated.

My guess is that you forgot one of those annotations.

However, we want inversify to provide developers with a nice user experience and one of the ways we do it is by providing nice error descriptions. I don't consider:

Error: Cannot read property 'name' of undefined

A user-friendly error and I want to fix it. Can you please help us by providing a small piece of code that can reproduce the issue?

It will help us a lot to accelerate the patching process.

Thanks!

@remojansen - Right, if you look at the code I linked, that's the exact project I'm working with. Here it is again, just in case:

https://github.com/atrauzzi/anecdote-engine/blob/master/src/Engine/ConfigurationReader.ts#L27-L46

I'm not sure I can shrink it given that I might suddenly stop encountering the bug if I make it too contrived. But I think my project is clean enough that you can check it out and run with it easily.

I have tried to reproduce your problem without success because the following file is missing:

import protobufMeta from "./Protobuf";

So it looks like I did in fact have some bad imports going on. Apologies for the runaround :)

Hi, I also have the same problem.
The index.ts (where do the bind)
I have this line kernel.bind<interfaces.Controller>(TYPE.Controller).to(RFMonitorController).inSingletonScope().whenTargetNamed(TAGS.RFMonitorController);
The problem here is I have other similar binds and they are working good.

Just for the record, I had this problem and it was caused by Typescript. I flushed the /ts-node folder and it worked then.

Hi @cguillemette, how would I go about flushing the ts-node folder doing this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inaiei picture inaiei  路  4Comments

remojansen picture remojansen  路  4Comments

Deviad picture Deviad  路  3Comments

asykes74 picture asykes74  路  4Comments

remojansen picture remojansen  路  4Comments