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 · 2 comments
Open

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

nfjdu opened this issue Sep 16, 2023 · 2 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

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