DI-compiler
DI-compiler copied to clipboard
ReferenceError: 1 argument required, but only 0 present
Hi. I followed you docs, but anyway keep getting this exception: ReferenceError: 1 argument required, but only 0 present. Note: You must use DI-Compiler (https://github.com/wessberg/di-compiler) for this library to work correctly. Please consult the readme for instructions on how to install and configure it for your project.
Here is my little test project setup: package.json
{
"name": "di-test-ts",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@wessberg/di": "^2.1.0",
"@wessberg/di-compiler": "^3.3.0",
"tsx": "^3.12.10",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/node": "^20.6.0"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"preserveValueImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
di.ts
import { DIContainer } from "@wessberg/di";
export interface IMyService {
testMyService: (str: string) => void;
}
export class MyService implements IMyService {
testMyService(str: string) {
console.log("testMyService", str);
}
}
export const container = new DIContainer();
container.registerSingleton<IMyService, MyService>();
container.get<IMyService>().testMyService("from di.ts");
index.ts
import { container, type IMyService } from "./di";
container.get<IMyService>().testMyService("from index.ts");
Note
If i run node --loader @wessberg/di-compiler/loader --loader tsx di.ts
- everything works as expected
But, if i try to use container from another file, i get that exception:
node --loader @wessberg/di-compiler/loader --loader tsx index.ts
Is this issue on your side or something wrong with my configs? Ty for help!
p.s. I am sure this tool is absolutely underrated, and i think this is partly due to problems with setting it up to be working , to play with it and make some tests. p.s.2. I hope it is still maintained)
Here is link to cloud example: sandbox
this happens to me too with tsx. it works fine with ts-node. node v21.1.0
node --import tsx --loader @wessberg/di-compiler/loader src/app.ts
Maybe i am too stupid to setup everything correctly.. but for me only last example works:
Here is working example: https://codesandbox.io/p/devbox/wessberf-di-commonjs-test-mlpzx4?file=%2Fsrc%2Findex.ts%3A9%2C41
If someone has an example of how can i build it and run built version it would be nice to have a look at it, ty.
btw, does someone use this lib in production? is this project still alive at all?
btw, does someone use this lib in production? is this project still alive at all?
we use it in production ( we compile when we run, so not running into this problem)
that said, we are actively considering alternatives, since the project seems somewhat dead lol
This lib seems like a true gem, but lack of live, working sandbox examples for everything listed in readme makes it little bit hard to understand how to work with it. Its just insane how projects like this fade out when projects like microsoft TSyringe has 350k weekly downloads… Hope author will continue with this project)