-
Notifications
You must be signed in to change notification settings - Fork 12k
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
SSR "window is not defined" Error in Angular 18 after Build and Serve #29885
Comments
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please? You can read here why this is needed. A good way to make a minimal repro is to create a new app via This might be related to your directory structure so its really important to get an accurate repro to diagnose this. |
Sorry, but as I mentioned earlier, since we were on Angular 15 and upgraded to Angular 18, I won't be able to reproduce this issue. What I can share is that we have tried different fixes:
I can also provide other TypeScript configuration files if you'd like. Here are the configuration files: 1.
|
If general if you need to access browser-only APIs or manipulate the DOM directly, the dedicated hooks should be used: Unfortunately, without a minimal reproduction, there’s not much we can investigate. |
Ok, so what’s the best way to update my current Angular project to Angular 17 SSR using NgModule-based modules, without standalone components or ESBuild, and keeping only Webpack? I followed the Angular upgrade guide, but I don’t have any info on doing it the way I want. |
The above mentioned hooks also with NgModules. Ultimately, without a reproduction, it's impossible to understand what the problem is. |
Which @angular/* package(s) are the source of the bug?
compiler-cli
Is this a regression?
Yes
Description
After upgrading to Angular 18 from Angular 15 and building an Angular SSR (Server-Side Rendering) application, I encountered a ReferenceError: window is not defined when running the application with npm run serve:ssr. The error appears to be caused by server-side code attempting to access the window object, which is not available in the server environment.
angular.json
package.json scripts
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
No response
The text was updated successfully, but these errors were encountered: