I'm encountering an error in my Angular 18 application related to sessionStorage. My code is throwing a ReferenceError: sessionStorage is not defined in the MyComponent. Here’s the relevant code snippet where the error occurs: export class MyComponent implements OnInit { constructor() { } ngOnInit(): void { const sessionId = sessionStorage.getItem('sessionId'); // Error occurs here // Other logic } } Another interesting part is, I don't get this error when I use sesssionStorage.setitem export class GenerateInfo { public sessionId!: string; constructor() { } setSessionIdToStorage(): void { sessionStorage.setItem('sessionId', JSON.stringify(this.sessionId)); // No error here // Other logic } } Continue reading...