Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: v6 no longer handles singletons with value undefined #1518

Open
simhnna opened this issue Jul 26, 2023 · 4 comments
Open

regression: v6 no longer handles singletons with value undefined #1518

simhnna opened this issue Jul 26, 2023 · 4 comments
Assignees
Milestone

Comments

@simhnna
Copy link

simhnna commented Jul 26, 2023

This code works without errors using inversify 5.1 but fails in inversify 6

import { Container } from "inversify";

const container = new Container();
const s = Symbol('foo');
container.bind(s).toConstantValue(undefined);


console.log(container.get(s));

container.unbindAll();

produces:

/project/node_modules/inversify/lib/container/container.js:453
        var constructor = Object.getPrototypeOf(instance).constructor;
                                 ^

TypeError: Cannot convert undefined or null to object
    at Function.getPrototypeOf (<anonymous>)
    at Container._deactivate (/project/node_modules/inversify/lib/container/container.js:453:34)
    at Container._deactivateIfSingleton (/project/node_modules/inversify/lib/container/container.js:634:21)
    at Container._deactivateSingletons (/project/node_modules/inversify/lib/container/container.js:639:31)
    at /project/node_modules/inversify/lib/container/container.js:287:19
    at /project/node_modules/inversify/lib/container/lookup.js:113:13
    at Map.forEach (<anonymous>)
    at Lookup.traverse (/project/node_modules/inversify/lib/container/lookup.js:112:19)
    at Container.unbindAll (/project/node_modules/inversify/lib/container/container.js:286:33)
    at file:///project/inversify-bug.mjs:10:11
@simhnna simhnna changed the title regression in inversify 6: no longer handles singletons with value undefined regression: v6 no longer handles singletons with value undefined Jul 26, 2023
@simhnna
Copy link
Author

simhnna commented Jul 26, 2023

Actually primitive types apparently also cause issues. Using a number instead of undefined results in the following stacktrace

/project/node_modules/inversify/lib/container/container.js:467
            throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex.message));
                  ^

Error: onDeactivation() error in class Number: Reflect.hasMetadata is not a function
    at Container._deactivate (/project/node_modules/inversify/lib/container/container.js:467:19)
    at Container._deactivateIfSingleton (/project/node_modules/inversify/lib/container/container.js:634:21)
    at Container._deactivateSingletons (/project/node_modules/inversify/lib/container/container.js:639:31)
    at /project/node_modules/inversify/lib/container/container.js:287:19
    at /project/node_modules/inversify/lib/container/lookup.js:113:13
    at Map.forEach (<anonymous>)
    at Lookup.traverse (/project/node_modules/inversify/lib/container/lookup.js:112:19)
    at Container.unbindAll (/project/node_modules/inversify/lib/container/container.js:286:33)
    at file:///project/inversify-bug.mjs:10:11
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

@simhnna
Copy link
Author

simhnna commented Sep 28, 2023

I'm happy to contribute to make this work again if it's intended to work with primitive types. If it's not it would be nice to state that somewhere

@PodaruDragos
Copy link
Member

yes please, PR welcome

@Jameskmonger
Copy link
Member

Added to milestone 6.0.3, we will aim to resolve this regression as a priority. cc @PodaruDragos

@Jameskmonger Jameskmonger added this to the 6.0.3 milestone Dec 17, 2023
@Jameskmonger Jameskmonger self-assigned this Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants