Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: 1 argument required, but only 0 present #27

Open
nfjdu opened this issue Sep 16, 2023 · 6 comments
Open

ReferenceError: 1 argument required, but only 0 present #27

nfjdu opened this issue Sep 16, 2023 · 6 comments

Comments

@nfjdu
Copy link

nfjdu commented Sep 16, 2023

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
image

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)

@nfjdu
Copy link
Author

nfjdu commented Sep 16, 2023

Here is link to cloud example: sandbox

@elee1766
Copy link

elee1766 commented Jan 31, 2024

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

@nfjdu
Copy link
Author

nfjdu commented Jun 30, 2024

Maybe i am too stupid to setup everything correctly.. but for me only last example works:
image

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.

@nfjdu
Copy link
Author

nfjdu commented Jun 30, 2024

btw, does someone use this lib in production? is this project still alive at all?

@elee1766
Copy link

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

@nfjdu
Copy link
Author

nfjdu commented Jun 30, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants