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

Fails to resolve dependencies with Vite #240

Open
leo1553 opened this issue Apr 18, 2024 · 1 comment
Open

Fails to resolve dependencies with Vite #240

leo1553 opened this issue Apr 18, 2024 · 1 comment
Assignees

Comments

@leo1553
Copy link

leo1553 commented Apr 18, 2024

Describe the bug

When trying to resolve a token with one or more dependencies, the error TypeInfo not known for "Bar" is thrown.

To Reproduce

Reproduced on StackBlitz

Sample code:

import '@abraham/reflection';

import { container, singleton } from 'tsyringe';

@singleton()
export class Foo {
  constructor() {}
}

@singleton()
export class Bar {
  constructor(public foo: Foo) {}
}

console.log(container.resolve(Foo)); // Works
console.log(container.resolve(Bar)); // Throws Uncaught Error: TypeInfo not known for "Bar"

Tested with:

{
  "scripts": {
    "start": "vite",
    "build": "tsc && vite build"
  }
}

Expected behavior

The token Bar should have been successfully resolved with its Foo dependency set.

Versions

{
  "devDependencies": {
    "typescript": "^4.9.5",
    "vite": "^5.2.9"
  },
  "dependencies": {
    "@abraham/reflection": "^0.12.0",
    "tsyringe": "^4.8.0"
  }
}

References

@leo1553
Copy link
Author

leo1553 commented Apr 18, 2024

This can be fixed using @rollup/plugin-typescript:

  • Install @rollup/plugin-typescript
  • Create vite.config.mjs:
    import typescript from '@rollup/plugin-typescript';
    import { defineConfig } from 'vite';
    
    export default defineConfig({
      plugins: [typescript()]
    })
  • Set "module": "ESNext" in tsconfig.json

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

No branches or pull requests

2 participants