Angular SSR build failure when using dynamically loaded components
See original GitHub issue🐞 Bug report
What modules are related to this issue?
- aspnetcore-engine
- builders
- common
- express-engine
- hapi-engine
Is this a regression?
Yes, the previous version in which this bug was not present was: ^8
Description
We successfully use dynamically loaded components with custom HTML containing Angular components without using SSR, with latest @angular/* packages and AOT set to false
But attempting to build with SSR fails not recognizing code related to the Angular compiler and component decorator(s)
There is no option like AOT for SSR builder in angular.json
, and setting optimization
to false
doesn’t resolve the issue
🔬 Minimal Reproduction
I have created a repo demonstrating the issue, containing the code below:
private async createComponent(template: string) {
const metadata = {
template: template,
};
const cmpntCls = class DynamicComponent {};
const decoratedCmpntCls = Component(metadata)(cmpntCls);
@NgModule({
imports: [CommonModule, CounterModule],
declarations: [decoratedCmpntCls],
})
class RuntimeComponentModule {}
const targetMdl = await this.compiler.compileModuleAsync(RuntimeComponentModule);
return [decoratedCmpntCls, targetMdl];
}
More with a readme at the repo: https://github.com/adigourdi/angular-ssr-dynamic-html
🔥 Exception or Error
Error: src/app/app.component.ts:43:21 - error NG1010: Value at position 0 in the NgModule.declarations of RuntimeComponentModule is not a reference
Value could not be determined statically.
43 declarations: [decoratedCmpntCls],
~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:43:22
43 declarations: [decoratedCmpntCls],
~~~~~~~~~~~~~~~~~
Unable to evaluate this expression statically.
src/app/app.component.ts:39:31
39 const decoratedCmpntCls = Component(metadata)(cmpntCls);
~~~~~~~~~~~~~~~~~~~
Unable to evaluate this expression statically.
src/app/app.component.ts:39:31
39 const decoratedCmpntCls = Component(metadata)(cmpntCls);
~~~~~~~~~
Unable to evaluate an invalid expression.
🌍 Your Environment
Angular CLI: 12.2.12
Node: 14.17.6
Package Manager: npm 6.14.15
OS: linux x64
Angular: 12.2.12
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.12
@angular-devkit/build-angular 12.2.12
@angular-devkit/core 12.2.12
@angular-devkit/schematics 12.2.12
@nguniversal/builders 12.1.3
@nguniversal/express-engine 12.1.3
@schematics/angular 12.2.12
rxjs 6.6.7
typescript 4.3.5
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12
Top Results From Across the Web
Angular SSR, Dynamic Page Won't Load - Status 504
Directly connecting to a dynamic route (dashboard, bot page), seems to not work. However, directly connecting to docs does work.
Read more >Server-side rendering (SSR) with Angular Universal
This guide describes Angular Universal, a technology that renders Angular applications on the server. A normal Angular application executes in the browser, ...
Read more >Server-side Rendering (SSR) with Angular Universal
In client-side rendering, the partial web page is returned by the server without dynamic data, but it offers the client-side scripts that are...
Read more >Angular Universal & Server-side rendering Deep-Dive - Medium
Dynamic SSR is the concept that there will be a live Node server spun up that whenever a Route is hit, it will...
Read more >Server Side rendering with Angular universal 14 - Ganatan
By clicking on main.js we open this file which contains the text "Features" Let's run a compilation with npm run build. · The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the reply Alan, but I have already updated my docker image to use node_modules
For the record, removing
bundleDependencies: false
or setting it to true results in the errors below (new ng@12 project with node@14)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.