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

question: Using Typedi with Vite - Returning ContainerInstance2 #966

Open
lucastanger opened this issue Dec 12, 2022 · 3 comments
Open

question: Using Typedi with Vite - Returning ContainerInstance2 #966

lucastanger opened this issue Dec 12, 2022 · 3 comments
Labels
type: question Questions about the usage of the library.

Comments

@lucastanger
Copy link

I was trying to...
We are using an Nx monorepo for our projects. As Nx included Vite in its most recent release, we wanted to try it out in one of our react projects. The brain of our applications is a library that injects services via typedi, which worked without any problems.

The problem:
Since we changed to Vite, typedi is not injecting the services anymore. One thing i noticed was that instead of returning the Service as expected it returned an Instance of ContainerInstance2. I could not find any explanation why this suddenly occurs?

@lucastanger lucastanger added the type: question Questions about the usage of the library. label Dec 12, 2022
@lucastanger lucastanger changed the title question: Using Typedi with Vite question: Using Typedi with Vite - Returning ContainerInstance2 Dec 12, 2022
@attilaorosz
Copy link
Member

I have no experience with vite but the container instance is injected as the last parameter always, so it seems like your service is not recognized for some reason. Could you please setup a repo where we could test?

@JoCat
Copy link

JoCat commented Mar 16, 2023

I ran into a similar problem, it is because esbuild (it is used under the hood in vite) intentionally does not support emitDecoratorMetadata (evanw/esbuild#257), this causes decorators to not work.

I was helped by the solution https://github.com/anatine/esbuildnx/tree/main/packages/esbuild-decorators

@asika32764
Copy link

This works for me.

import { esbuildDecorators } from '@anatine/esbuild-decorators';

export default defineConfig(() => {
  return {
    ...
    optimizeDeps: {
      esbuildOptions: {
        plugins: [
          esbuildDecorators({
            tsconfig: 'tsconfig.app.json',
          })
        ],
      }
    }
  };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

4 participants