P
P
Pashchuk Ilya2021-11-13 09:04:01
Angular
Pashchuk Ilya, 2021-11-13 09:04:01

How to solve the problem when building an Angular project?

Guys I have a problem when I call ng name-project: prerender

Prerendering 12 route(s) to /Users/twic/var/www/newhope/dist/newhope-surrogacy...ERROR NetworkError
  at XMLHttpRequest3.send (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2437770)
  at Observable._subscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:123191)
  at Observable._trySubscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2268050)
  at Observable.subscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2267832)
  at SwitchMapOperator.call (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2315482)
  at Observable.subscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2267686)
  at CatchOperator.call (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2301714)
  at Observable.subscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2267686)
  at DoOperator.call (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2319735)
  at Observable.subscribe (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:2267686)
ERROR TypeError: Cannot set properties of null (setting 'statusCode')
  at HopeNotComponent.ngOnInit (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/185.js:1:12034)
  at callHook (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:174673)
  at callHooks (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:174290)
  at executeInitAndCheckHooks (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:173626)
  at refreshView (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:280356)
  at refreshEmbeddedViews (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:300665)
  at refreshView (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:280484)
  at refreshComponent (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:301386)
  at refreshChildComponents (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:277202)
  at refreshView (/Users/twic/var/www/newhope/dist/newhope-surrogacy/server/main.js:1:280981)
✔ Prerendering routes to /Users/twic/var/www/newhope/dist/newhope-surrogacy complete.


does the problem occur? what should i do with the solution?

export class HopeNotComponent implements OnInit {

  constructor(
    @Inject(PLATFORM_ID) private platformId: object,
    @Optional() @Inject(RESPONSE) private response: any,
    protected metaService: Meta,
    protected titleService: Title,) {
  }

  ngOnInit(): void {
    this.titleService.setTitle(ceo404Page.TITLE);
    this.metaService.updateTag({name: 'description', content: ceo404Page.DESCRIPTION});
    this.metaService.updateTag({name: 'keywords', content: ceo404Page.KEYWORDS});

    if (isPlatformServer(this.platformId)) {
      // this.response.status(404);
      this.response.statusCode = 404;
      this.response.statusMessage = '404 - Page Not Found';
    }
  }
}


These are screens [1] [2]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2021-11-13
@kttotto

It's all in the message

ERROR TypeError: Cannot set properties of null (setting 'statusCode')

Cannot initialize the field, because it's null
this.response is definitely undefined or null at the time the component is opened.
Add a check
if (!!this.response) {
  this.response.statusCode = 404;
  this.response.statusMessage = '404 - Page Not Found';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question