InversifyJS를 사용하여 NodeJS/TypeScript 프로젝트를 설정하려고하는데 바닥에서 떨어지는 데 문제가 있습니다. 나는 지난 며칠 동안 이것을보고 있었고 문제를 파악할 수 없었다. 모든 것이 올바르게 빌드,하지만 나는 다음과 같은 오류가 노드 서버를 시작하려고 : 나는 NodeJS의 v6.2.2을 실행하는거야InversifyJS - injectable이 (가) 함수가 아닙니다.
TypeError: inversify_1.injectable is not a function
(윈도우 10의 x64) 및이 타이프 1.8이 설치되어 있어야합니다. VS2015와 gulp를 사용하여 건물을 시험해 보았습니다. 다음은 동일한 오류가 발생하는 시도한 최소한의 예제입니다. 나는 틀린 무엇인가 볼 수 없다. 그러나 나는 명백한 무엇인가 놓치고 있어야한다. (옆으로 조잡 코드는 여전히 작동합니다.)
server.ts :
/// <reference path="./node_modules/reflect-metadata/reflect-metadata.d.ts" />
/// <reference path="./node_modules/inversify-dts/inversify/inversify.d.ts" />
/// <reference path="./typings/index.d.ts" />
import "reflect-metadata"
import { Application } from "./app/app"
import { ITest, TestClass } from "./app/testclass"
import { Kernel, injectable, inject } from "inversify"
var kernel = new Kernel();
kernel.bind<ITest>("ITest").to(TestClass);
kernel.bind<Application>(Application).to(Application);
var app = kernel.get<Application>(Application);
app.initialize();
응용 프로그램은/
/// <reference path="../node_modules/inversify-dts/inversify/inversify.d.ts" />
/// <reference path="../typings/index.d.ts" />
import * as Hapi from "hapi";
import { inject, injectable } from "inversify"
import { ITest } from "../app/testclass"
@injectable()
export class Application {
private testClass: ITest;
constructor(@inject("ITest") test: ITest) {
this.testClass = test;
};
initialize() {
var server = new Hapi.Server({
connections: {
router: {
isCaseSensitive: false,
stripTrailingSlash: true
}
}
});
server.connection({
port: '3000',
host: 'localhost'
});
server.route({
method: 'GET',
path: '/',
handler: (request: Hapi.Request, reply: Hapi.IReply) => {
var str = this.testClass.test();
reply(str);
}
});
server.start(function() {
console.log('Server running at:', server.info.uri);
});
}
}
응용 프로그램을 app.ts/testclass.ts
/// <reference path="../node_modules/inversify-dts/inversify/inversify.d.ts" />
import { injectable } from "inversify"
export interface ITest {
test(): string;
}
@injectable()
export class TestClass implements ITest {
test(): string {
return "testing";
}
}
tsconfig.json
{
"files": [
"server.ts",
"app/app.ts",
"app/testclass.ts"
],
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"target": "es6",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "../release/"
}
}
노드에서
전체 오류 출력은 :
C:\Projects\inversifytest\release\app\app.js:50
inversify_1.injectable(),
^
TypeError: inversify_1.injectable is not a function
at Object.<anonymous> (C:\Projects\inversifytest\release\app\app.js:50:17)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Projects\inversifytest\release\server.js:6:15)
at Module._compile (module.js:541:32)
고마워, 나는 똑같은 바보 같은 실수를했다. –