analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.5k stars 237 forks source link

Angular services in libraries that depend on services that require a clientProvider work in Astro dev builds but not in production builds #1206

Closed lonevox closed 1 week ago

lonevox commented 1 month ago

Please provide the environment you discovered this bug in.

Astro preview on local machine.

Reproduction (this uses Angular 16 as that is what my project uses): https://stackblitz.com/edit/withastro-astro-zktjyx?file=astro%2Fpackage.json

NOTE: The bug can't be encountered in StackBlitz. You must download the StackBlitz project and run it locally.

The reproduction project ./my-workspace directory is a fresh Angular workspace containing a library project. This library exports a single Angular service MyLibService that depends on HttpClient. The reproduction project ./astro directory is a fresh Astro project with an index page containing a component called TestComponent. The component depends on MyLibService, and as such needs to define a client provider for the HttpClient.

To encounter the bug, run the following commands in the reproduction project:

cd my-workspace
yarn
yarn build
cd ../astro
yarn
yarn astro dev

The Astro project should have run correctly (there should be a webpage with the text "my-lib works!"). Cancel the running page and execute the following commands:

yarn astro build
yarn astro preview

The result is a blank page with a NG0203 error in the console.

Which area/package is the issue in?

astro-angular

Description

Unfortunately this is a difficult bug to describe, but hopefully the issue title and bug reproduction in the first section explain it well enough.

Please provide the exception or error you saw

NG0203

Other information

No response

I would be willing to submit a PR to fix this issue

lonevox commented 1 month ago

The reproduction project isn't working. I will try and fix it tomorrow.

lonevox commented 1 month ago

The reproduction project is fixed. I've updated the instructions accordingly. Unfortunately the bug doesn't appear in StackBlitz (it seems to fail too early) so you need to download the StackBlitz project and run it locally.

brandonroberts commented 1 week ago

You should use both renderProviders and clientProviders so it registers the providers on server render and client hydration