ngx-cookie: Could not resolve @nguniversal/express-engine/token

I’m submitting a … (check one with “x”)

[ X] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior Version 4.1.1 breaks when building angular project.

ERROR in ../ngx-cookie/ngx-cookie.ts(10,23): Error during template compile of 'CookieBackendService'
  Could not resolve @nguniversal/express-engine/tokens relative to [object Object]..

Reproduction of the problem Install the lastest package (4.1.1) and ng serve or ng build

Please tell us about your environment:

  • ngx-cookie version: 4.1.1

  • Angular version: 7.0.3

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 54
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Same, it should be included in package.json as a dependency but it is not.

workaround => add it to your project: npm i @nguniversal/express-engine -D

in my case, I downgraded dependency to version v4.0.2, working now.

"ngx-cookie": "4.0.2"

Especially frustrating when you don’t even use server side rendering!

Same error with latest versions:

  • angular 7.1.4
  • angular-cli 7.1.4
  • angular-devkit/build-angular 0.11.4
  • ngx-cookie 4.1.2
ERROR in ./node_modules/ngx-cookie/fesm5/ngx-cookie.js
Module not found: Error: Can't resolve '@nguniversal/express-engine/tokens' in '/Users/byakubchik/Desktop/publish/node_modules/ngx-cookie/fesm5'

However, it works after: npm install @nguniversal/express-engine --saveDev thank you to @shprink

I also encountered this problem when ‘ng build’

it needs ‘npm install @nguniversal/express-engine’, however anyone with obsessive-compulsive disorder don’t want to install this。

Angular CLI:

[ng]
[ng] ERROR in ./node_modules/ngx-cookie/fesm5/ngx-cookie.js
[ng] Module not found: Error: Can't resolve '@nguniversal/express-engine/tokens' in 'D:\Sources\SPL\mobile-app\node_modules\ngx-cookie\fesm5'
[ng] i 「wdm」: Failed to compile.

I’m not sure what the changes you made to ask this, I see it is in package.json as a dependency but it is maybe the build itself broken? I see it in peerDependencies in published version but in dependencies in the source file.

And I’m using version 4.1.2!

Edit: Oh I see it is commit 1956eff to blame.

Still an issue, I don’t see why this should be mandatory dependency.

Agree. One year has passed since ticked was opened and problem still exists: ngx-cookie: 4.1.2. The quality of JavaScript packets are amazing…

Still an issue, I don’t see why this should be mandatory dependency.

any update about this issue?

Fixed.

@MarkoSulamagi I had ^4.0.2 in package.json, all working fine for me (if I rm -rf node_modules && npm install) BUT on someone else’s computer (same os, same node & npm versions), cloning the project for the first time, the error appeared. I don’t know why, maybe npm cache? Haven’t tried npm ci though. Anyway, the solution that actually permitted me to still sleep at night was replacing ^4.0.2 with 4.0.2 in package.json 😁 as I knew that it was working fine when I created the project with 4.0.2. Didn’t invest any time in checking in what version it broke.

@almothafar in my experience, most apps have/need authorization. In order to properly render a protected route on the server (or even an unprotected route that still needs to display some data about the current user), you need that token or whatever you store for authorization. And since we don’t have localStorage on the server, that being a client-side only mechanism, the only way I see is to use cookies to store stuff like a token, because you need to read and use that token in your request headers while rendering server side as well, not just from the browser. That being said, I ended up writing my own cookie service long ago, since it’s not that hard to do.