Unable to set extraProviders for prerender builder.
asgerjensen opened this issue · 2 comments
🐞 Bug report
What modules are related to this issue?
- builders
- common
- express-engine
Is this a regression?
Unknown
Description
Unable to pass extraProviders
for prerender worker, like i can for Engines
universal/modules/builders/src/prerender/worker.ts
Lines 98 to 103 in 5974f8e
vs
universal/modules/common/engine/src/engine.ts
Lines 96 to 100 in 5974f8e
🔬 Minimal Reproduction
In the server-app-module, read a
Provide this in the engine in server.ts
const rootProviders = [
// these providers are first in line,
// so you cant override anything setup in app.module
{
provide: "ENV_ORIGIN_URL",
useValue: 'some-value',
},
...
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
server.engine(
"html",
ngExpressEngine({
bootstrap: AppServerModule,
providers: rootProviders,
})
);
This value is available in the app.server.module.ts
@NgModule({
declarations: [],
imports: [AppModule, ServerModule],
providers: [
{
provide: ORIGIN_URL,
useExisting: "ENV_ORIGIN_URL",
},
],
bootstrap: [AppComponent],
})
export class AppServerModule {}
But when running prerender, it does not use the engine. It just imports the AppServerModule from main.js
, so any configuration done via extraProviders is lost.
Maybe, since the prerender worker is just grabbing expected exports from main.js, it could just be supported that it looked for an export called rootExtraProviders or some such, which would be an array of StaticProvider
?
🔥 Exception or Error
taskId: 8,
result: null,
error: NullInjectorError: NullInjectorError: No provider for ENV_ORIGIN_URL!
🌍 Your Environment
"@angular/animations": "16.1.9",
"@angular/cdk": "16.1.8",
"@angular/common": "16.1.9",
"@angular/compiler": "16.1.9",
"@angular/core": "16.1.9",
"@angular/forms": "16.1.9",
"@angular/google-maps": "^15.2.1",
"@angular/material": "16.1.8",
"@angular/platform-browser": "16.1.9",
"@angular/platform-browser-dynamic": "16.1.9",
"@angular/platform-server": "16.1.9",
"@angular/router": "16.1.9",
"@angular-devkit/build-angular": "16.1.8",
"@angular-devkit/core": "16.1.8",
"@angular-devkit/schematics": "16.1.8",
"@angular-eslint/eslint-plugin": "16.0.3",
"@angular-eslint/eslint-plugin-template": "16.0.3",
"@angular-eslint/template-parser": "16.0.3",
"@angular/cli": "~16.1.0",
"@angular/compiler-cli": "16.1.9",
"@angular/language-service": "16.1.9",
"@angular/localize": "16.1.9",
"@nguniversal/express-engine": "16.1.3",
"@nguniversal/builders": "^16.2.0",
This is expected as when pre-rendering the AppServerModule
is used directly. As such it is recommended that you configure the server only providers in there and only configure providers in ngExpressEngine
where you need to provide values from the request/response or other providers that override the once configured in AppServerModule
.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.