Comments (13)
There a number of different errors here with different causes:
Error: projects/showcase/server.ts:12:18 - error TS2349: This expression is not callable.
is due toimport * as express from 'express';
which should be replaced withimport express from 'express';
whenesModuleInterop
is enabled.An unhandled exception occurred: window is not defined
- this is due to your code is not SSR compliant as you usewindow
examplewindow.clearInterval
. These should be replaced with non platform specific implementation example:clearInterval
.maplibre-gl
is also not compatble with SSR and thus, any of this could should be imported and used in https://angular.io/api/core/afterNextRender and https://angular.io/api/core/afterRender- DOM manipulation should be performed in the designed hooks. https://angular.io/api/core/afterNextRender and https://angular.io/api/core/afterRender
ERROR Error: Error retrieving icon :ngx-maplibre-gl!
, this is because accessing local assets is only done when using the new application builder. You can update your application to use the new esbuild based builder usingng update @angular/cli --name=use-application-builder
. You also need to use the fetch APIprovideHttpClient(withFetch())
.- Since your application requires
zone.js
, this also needs to be added in thepolyfills
section in yourangular.json
.
Note: enabling sourcemaps will give you better error stacktraces for runtime errors.
from angular.
Thanks for taking the time to look into this!
Note that I have always updated this small app using ng update
, and so these should've been added to the upgrade code.
Also everything you wrote here is not documented anywhere, so I think it would make sense to enrich the docs with some helpful tips.
- This is generated code that was added using
ng add @angular/ssr
I believe it should be fixed there. - Yes, I know maplibre is not SSR compatible, I'm sure I'm not the only one with this problem, the question is what to do in this case, adding a section about it to the docs will be helpful
- No clue what to do with this tip... What should I be looking for in my app?
- Am I using an old version of the builder? I'm using angular 17, shouldn't it be the defualt?
- Besides some post saying some application can be ran without zone.js I have found very little information about this, I think a section about it would be helpful in the official docs...
from angular.
Transferring to the FW repo since this is mostly due to lack of documentation
from angular.
@alan-agius4 there are still issues with the generated express code worth fixing...
Also I guess better error messages can help here and suggestions how to solve the problem I'm facing (like browser specific code etc).
I'm not saying the docs shouldn't improve, but the CLI can help too.
from angular.
@alan-agius4 , we got 1, 4, 5 done, so now it's a modern application
SPA.
We're still fighting these two steps you mentioned related to the transition to SSR:
- An unhandled exception occurred: window is not defined - this is due to your code is not SSR compliant as you use window example window.clearInterval. These should be replaced with non platform specific implementation example: clearInterval. maplibre-gl is also not compatble with SSR and thus, any of this could should be imported and used in https://angular.io/api/core/afterNextRender and https://angular.io/api/core/afterRender
- DOM manipulation should be performed in the designed hooks. https://angular.io/api/core/afterNextRender and https://angular.io/api/core/afterRender
Basically, they are the same thing, and the afterNextRender/afterRender doesn't seem like the right solution to the problem. We need to be able to define a boundary where the server-side rendering (or in this case pre-rendering) stops and the client-side rendering begins.
Here are how other frameworks specify this boundary:
- Astro has
client
directive - SolidStart has clientOnly
- Nuxt has
<ClientOnly>
- Next has "use client"
from angular.
Maybe the isPlatformBrowser can help define this boundary, if it's pre-render compatible
Article on the topic of conditional client rendering
from angular.
afterNextRender
runs only client side. This is what we recommend to setup client-side only libs.
from angular.
General experience - I've been making some progress with this approach, but I must admit it feels like a lot of work, and potentially very error prone, to go through and adapt each client component instead of a boundary and saying "from here and onwards" like most frameworks do.
ngOnInit - Using afterNextRender, instead of ngOnInit, often works, and now the app is at least building.
ngOnDestroy - Is there a client-only counterpart for ngOnDestroy as well? Currently I have to disable the content of the ngOnDestroy because it's being ran on the server. I need a way to do it client-side, so that I don't add memory leaks in the client.
ngOnChange - Where I normally use ngOnChange(changes=>{}) i now try to use the client-side afterRender, but since afterRender is not triggered by a change, it running at the wrong times, and it doesn't provide a changes
object I need in my onChange function . I don't know how to migrate this ngOnChange content to client-only.
prerender:true doen't prerender - Another thing, despite the prerender:true flag being on, I don't see .html files created for each route inside of dist at build time. I expected that based on this article which doesn't mention having to do anything but that https://angular.io/guide/prerendering
from angular.
Any help here would be greatly appreciated.
We were able to build the SSR part of things and it seems to be working mostly, but I can't get the prerender to work.
When I add it I get all the icon and window build errors again.
If I only set a single route to prerender using the routesFile
it still fails.
Is there a way to understand why the build is failing?
I'm getting the following cryptic error messages:
ERROR Error: Error retrieving icon :ngx-maplibre-gl!
at Object.error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-IR2AAQSL.mjs:2:10604)
at jo.error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:3179)
at de._error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2823)
at de.error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2583)
at $o._error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2823)
at $o.error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2583)
at $o._error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2823)
at $o.error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2583)
at $o._error (file:///Users/---/dev/temp/ngx-maplibre-gl/.angular/prerender-root/56821466-7aa6-4c21-a319-54117db33efb/chunk-5KM5SIJU.mjs:4:2823)
An unhandled exception occurred: window is not defined
When I set prerender: false
the build passes again.
from angular.
Using provideHttpClient(withFetch())
fixes the ERROR Error: Error retrieving icon :ngx-maplibre-gl!
during build time.
from angular.
We have managed to solve all the problems and make pre-render work.
This was a super painful experience due to lack of documentation, cryptic error messages and generally a poor developer experience.
I hope the docs and process can be improved as part of this issue.
If anyone is interested, the following is the relevant PR:
from angular.
How can I exclude a component from SSR in Angular 17?
I tried isPlatformBrowser, afterRender. But not working
alway got this error: self is not defined
from angular.
It is advised to create a reproduction and not screenshot an error.
This issue had been closed.
I advise to take a look at the showcase code to see how we solved all kinds of issues.
from angular.
Related Issues (20)
- `HttpInterceptorFn` Usage Notes Not Working Without Modifications HOT 2
- Issue with contentChild of reprojected content HOT 1
- Feature Request💥 Add Destructuring Support in @for Loops and async if's HOT 4
- Markdown parser incorrectly parses elements in links
- The links styles on the roadmap page are not being rendered correctly. HOT 2
- ADEV: incorrect rendering of lists in API symbol docs HOT 3
- Docs website is broken
- The `isThenable` function inside zone.js cause an unexpected exception
- Custom `injector` for templates breaks `@Host` inject flag
- devtools injector tree tab doesn't show a provider from root injector HOT 1
- Form Value does not update when signal changes. HOT 1
- Duplicate trusted type policy error when using an angular app with a webcomponent that embeds an angular app HOT 3
- apache server .htaccess configuration not working when setting sourceMap to true HOT 6
- Check if a http interceptor is provided
- @angular/forms email validator doesn't support internationalized addresses HOT 1
- provideExperimentalZonelessChangeDetection not working - In this configuration Angular requires Zone.js HOT 4
- Introducing `'use client'` to angular HOT 7
- Page https://angular.dev/tutorials/first-app/10-routing/ is not loading. HOT 1
- "Example Input Values" on "Class and style binding" do not render correctly
- docs: add doc for getters from NgForOfContext HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.