angular2-cookie icon indicating copy to clipboard operation
angular2-cookie copied to clipboard

Issue with Universal Support and CookieBackendService

Open Loni2Shoes opened this issue 8 years ago • 7 comments

I am tying to add this library to a universal-enabled project, using the Universal Support instructions.

The two module-level import statements suggested for use are:

import { CookieService } from 'angular2-cookie/services/cookies.service';
import { CookieBackendService } from 'angular2-cookie/services/cookies.backend.service';

with providers supplied in the following way:

providers: [
    {
      provide: CookieService,
      useClass: CookieBackendService
    }

However, this results in the following error:

Exception: Call to Node module failed with error: TypeError: Cannot read property 'headers' of undefined at CookieBackendService.get [as cookieString]

Is there anything else that I need to configure to get his working with Universal?

Loni2Shoes avatar Feb 17 '17 17:02 Loni2Shoes

@Loni2Shoes did you figure out what causes this?

jzahka avatar Apr 14 '17 13:04 jzahka

Anyone is working on this?

Skillnter avatar Apr 22 '17 05:04 Skillnter

have the same problem, but just when I'm using lazy loaded modules in my project

crebuh avatar May 02 '17 12:05 crebuh

From what I can tell this error stems from how you provide request and response in your express engine. The example in the angular universal repo makes them available as injectable tokens https://github.com/angular/universal/tree/master/modules/ng-express-engine#using-the-request-and-response

I've forked ngx-cookie (the new version of angular2-cookie) to use these injected tokens https://github.com/jzahka/ngx-cookie/commit/d5bc30cc585093834c2ecdc984daf5c4ca70a602#diff-93b0490d252f26a870ada20b3b97cbddR9

jzahka avatar May 02 '17 14:05 jzahka

I have the same issue, any progress or solution to this?

JKetelaar avatar May 18 '17 08:05 JKetelaar

@jzahka

which angular universal repo do you mean? the starter? I can't find anything related to cookies there

crebuh avatar Jun 20 '17 08:06 crebuh

I now upgraded my universal-starter project from 2.x to 4.0.0 and also upgraded the angular2-cookie to the ngx-cookie but still have the same problem not sure how to solve this issue

crebuh avatar Jul 19 '17 14:07 crebuh