tough-cookie: v2.5.0 : str.trim() is not a function

We’re using tough-cookie ^2.4.3 (which actually installs 2.5.0) with request ^2.88.0.

This code worked with 2.4.3 :

const cookiesJar = requestModule.jar();
 _.forEach(initialCookies, (cookie: Object) => {
 const newCookie = toughCookie.fromJSON(JSON.stringify(cookie));
 const hostUrl = `${initialOptions.protocol}//${initialOptions.host}/`;
 cookiesJar.setCookie(newCookie, hostUrl);
});

But we’re getting the following error with 2.5.0 :

TypeError: str.trim is not a function
 at Function.parse (node_modules/request/node_modules/tough-cookie/lib/cookie.js:429:13)
 at CookieJar.setCookie (node_modules/request/node_modules/tough-cookie/lib/cookie.js:1011:21)
 at CookieJar.setCookieSync (node_modules/request/node_modules/tough-cookie/lib/cookie.js:1402:18)
 at RequestJar.setCookie (node_modules/request/lib/cookies.js:25:20)

Any hint about what could cause this issue in 2.5.0?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 15
  • Comments: 24 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Screen Shot 2019-08-30 at 4 25 08 PM

typescript (cookie instanceof Cookie) return false.

@awaterma

workaround

jar.setCookie(JSON.stringify(cookie), '.teamaster.club')

I’m still seeing this with v3.0.1.

$ npm ls --depth=0
+-- @types/commander@2.12.2
+-- @types/inquirer@6.0.3
+-- @types/node@12.0.10
+-- @types/request-promise-native@1.0.16
+-- @types/tough-cookie@2.3.5
+-- commander@2.20.0
+-- idx@2.5.6
+-- inquirer@6.4.1
+-- request@2.88.0
+-- request-promise-native@1.0.7
+-- tough-cookie@3.0.1
`-- typescript@3.5.2

Thanks @gombosg.

instanceof definitely goes on an actual Function object, so if you have two functions named Cookie (the constructor), the instanceof and == and === operators will all return false.

FWIW, I’m able to reproduce this in a test now with request 2.88.0 and node 11.4.0. I’ll look into it again later today.