Skip to content

NullInjectorError: R3InjectorError(Environment Injector)[InjectionToken REQUEST -> InjectionToken REQUEST]: #28838

@illunix

Description

@illunix

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

Yes

Description

 constructor() {
    const request = inject(REQUEST, { optional: true });
    console.log(request)
    if (request) {
      const cookie = request.headers.get('cookie');
      console.log(cookie)
      console.log('Server received a request', request.url);
    }

    const reqContext = inject(REQUEST_CONTEXT, { optional: true }) as {
      server: string;
    };
    if (reqContext) {
      // The context is defined in the server*.ts file
      this.server = reqContext.server;

      // Store this as this won't be available on hydration
      this.transferState.set(this.serverKey, this.server);
    }
    this.server = this.transferState.get(this.serverKey, '');
  }

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

R3InjectorError(Environment Injector)[InjectionToken REQUEST -> InjectionToken REQUEST]:

Please provide the environment you discovered this bug in (run ng version)

Angular 19.0.0-rc.0 
Windows 11

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions