Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: str.trim is not a function (Request-Promise/Tough-Cookie)

I am having similar problem as discussed here: https://github.com/request/request-promise/issues/183

I am using [email protected] and [email protected]

And getting the same error:

TypeError: str.trim is not a function

I also played around with npm-dedupe

enter image description here

Any clue,

My code looks like this:

let cookie = new tough.Cookie({domain: '.companyName.ninja',
  httpOnly: true,
  name: '_application_session',
  path: '/',
  secure: false,
  value: 'f044888d39e2d19126716d9f54028700' })
let cookieJar = request.jar()
cookieJar.setCookie(cookie, 'http://application.companyName.ninja/')
options.jar = cookieJar
like image 547
Kapil Chokhawala Avatar asked May 25 '18 00:05

Kapil Chokhawala


People also ask

What is typeerrror trim is not a function?

If we call the trim () method on the value that is not of a string type, JavaScript will throw a TypeError: trim is not a function. In this tutorial, we will look at what is TypeErrror: trim is not a function error and how to resolve them with examples. What is TypeError: trim is not a function error?

Is string trim a function in Firebase?

But it displays error TypeError: string.trim is not a function. Please help why is this so. const isEmpty = (string) => { if (string.trim () === '') return true; else return false; }; This is to check the whether a string is empty or not. I'm making a react project with firebase. Are you sure string is a string?

Is string trim() a string?

Also why not just string => string.trim () === ''? Yes.. String is a string. I don't know what causing up the problem. Well e.g. "".trim will tell you it is a function, so either string isn't a string or you're on some pre-ES5 runtime that doesn't have the method.

How to trim a string in an array in JavaScript?

If the value is a string, we return the result of calling the trim method, otherwise we return an empty string for consistency. If you want to trim all strings in an array, use the map method to iterate over the array and call the trim method on each string. The map method takes a function and calls it with each element in the array.


1 Answers

Change line

cookieJar.setCookie(cookie, 'http://application.companyName.ninja/')

to

cookieJar.setCookie(cookie.toString(), 'http://application.companyName.ninja/') 

(use toString() method).

like image 200
kmaci Avatar answered Nov 05 '22 06:11

kmaci