如何解决错误[ERR_ASSERTION]:构造函数已存在! (“” inversify-restify-utils“:” ^ 3.4.0“)和(”“ inversify-restify-utils”:“ ^ 3.4.0”)

时间:2019-03-26 16:25:36

标签: node.js typescript restify inversifyjs

node_modules / restify-errors / lib / index.js:67     assert.equal(typeof module.exports [name],'undefined',            ^ AssertionError [ERR_ASSERTION]:构造函数已经存在!

"inversify": "^4.13.0",
"inversify-binding-decorators": "^4.0.0",
"inversify-restify-utils": "^3.4.0",
"js-yaml": "^3.12.0",
"lodash": "^4.17.11",
"reflect-metadata": "^0.1.12",
"restify": "^7.2.1",
"restify-cors-middleware": "^1.1.1",
"winston": "^3.0.0"
private setPlugins(): void {
        const cors = corsMiddleware(this.config.cors);

        this.server.pre(cors.preflight);

    this.server.use(
        restify.plugins.acceptParser(this.server.acceptable),
        cors.actual
    );
}

它应该能够运行

npm run serve

堆栈跟踪

/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)

1 个答案:

答案 0 :(得分:0)

此模块附带了一组构造函数,可用于使用默认状态代码来更新Error对象。

npm i restify-errors --save-dev

只需将此软件包安装到您的项目中,因为在用于Inversifyjs时是必需的