InversifyJS: Cannot find name 'Controller' (express-utils)
Expected Behavior
The Controller should be found.
Current Behavior
An error is thrown (in stack trace at the bottom). Short Version Cannot find name Controller
Possible Solution
Currently I don´t have one.
Steps to Reproduce (for bugs)
- Create a file with the following Testcode:
import { injectable, interfaces, Kernel } from 'inversify';
import { Controller, InversifyExpressServer, TYPE } from 'inversify-express-utils';
const kernel: interfaces.Kernel = new Kernel();
kernel.bind<Controller>(TYPE.Controller).to(MyController).whenTargetNamed('MyController');
@injectable()
@Controller('/api')
class MyController {
constructor() {
console.log('do something');
}
}
- Try running it with ts-node
Context
The error is thrown in line 5. But in line 2 the Controller is imported so the error should not be thrown.
The code is started with ts-node test.ts, but trying to compile it with tsc test.ts the same error is thrown.
Your Environment
- inversify Version used: 2.0.0
- inversify-express-utils Version used: 2.0.1
- Environment name and version (e.g. Chrome 39, node.js 5.4): node.js v6.3.1
- Operating System and version (desktop or mobile): Desktop
- Link to your project: sfus-worker link refers to the branch I am working on.
Stack trace
src/master/api/api.ts (15,17): Cannot find name 'Controller'. (2304)
at getOutput (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:258:17)
at /home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:267:16
at Object.compile (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:403:17)
at loader (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:289:33)
at Object.require.extensions.(anonymous function) [as .ts] (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:306:14)
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)src/master/api/api.ts (15,17): Cannot find name 'Controller'. (2304)
at getOutput (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:258:17)
at /home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:267:16
at Object.compile (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:403:17)
at loader (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:289:33)
at Object.require.extensions.(anonymous function) [as .ts] (/home/me/.nvm/versions/node/v6.3.1/lib/node_modules/ts-node/src/index.ts:306:14)
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)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (11 by maintainers)
Thanks! 😄 I will document here the fix…
To fix this problem you need to use
inversify-express-utils@2.0.2then you can import both interfaces and Controller decorator:@remojansen thanks! Working now. Ideally, would be nice to be able to import
Controlleras is, but that’s just me being too picky 😄 Thank you!