inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.29k stars 716 forks source link

[ERR_ASSERTION]: Constructor already exists! (restify@7.1.1 + inversify-restify-utils@3.3.1) #847

Open hlibco opened 6 years ago

hlibco commented 6 years ago

Similar to the closed issue #703 (but with a newer version of restify)

Expected Behavior

It should start the restify server without problems.

Current Behavior

As soon as restify is imported an error is thrown: [ERR_ASSERTION]: Constructor already exists!

Possible Solution

To use inversify-restify-utils@3.3.1 I had to downgrade Restify to restify@6.3.2

Steps to Reproduce (for bugs)

Clone the following repo: https://github.com/hlibco/restify-inversify-constructor-error

  1. install dependencies yarn install or npm install
  2. run yarn start or npm start
  3. you should get the error
node_modules/restify-errors/lib/index.js:67
    assert.equal(typeof module.exports[name], 'undefined',
           ^
AssertionError [ERR_ASSERTION]: Constructor already exists!

Your Environment

    "inversify": "4.11.1",
    "inversify-restify-utils": "3.3.1",
    "reflect-metadata": "^0.1.12",
    "restify": "7.1.1",

Stack trace

/Users/earth/git-public/restify-inversify-problem/node_modules/restify-errors/lib/index.js:67
    assert.equal(typeof module.exports[name], 'undefined',
           ^
AssertionError [ERR_ASSERTION]: Constructor already exists!
    at Object.makeConstructor (/Users/earth/git-public/restify-inversify-problem/node_modules/restify-errors/lib/index.js:67:12)
    at Object.<anonymous> (/Users/earth/git-public/restify-inversify-problem/node_modules/restify/lib/errorTypes.js:5:8)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/earth/git-public/restify-inversify-problem/node_modules/restify/lib/index.js:14:1)
hlibco commented 6 years ago

Hi @remojansen I saw you closed the issue #703 (similar to the one I just opened) by suggesting to upgrade to restify@6.3.4. It didn't work to be (but 6.3.2 did). However, upgrading to restify@7.1.1 (latest - at the time of this post), the error persists.

Any idea of how inversify-restify-utils users should proceed?

hlibco commented 6 years ago

The inversify-restify-utils on github has its dependencies being updated by greenkeeper. That's great. It would be even better if the up-to-date version on github could be published to NPM. It would fix the #847

I manually changed the version of restify which inversify-resity-utils dependends on (from 6.3.2 to 7.1.1) and it fixed the issue.

mgebundy commented 6 years ago

I'm also blocked upgrading to the most recent versions of Inversify and Restify by this. Could a new version be published to npm? That would be incredibly helpful.

jinghualin commented 6 years ago

I resolved this problem in current version

From restify version 6 I have same problem, when I do not install the restify-errors module.

mgebundy commented 6 years ago

@hlibco inversify-restify-utils has been updated, the new v3.4 should be compatible with the most recent version of inversity and restify v7