TypeError: str.charCodeAt is not a function
Asked Answered
A

0

9

I updated to node version 6 today and that might've broke something. I tried to get back to node 5.10 but the issue didn't go away. Can this be related to the new V8 engine that is shipped by node v6?

Has anyone experienced this? Any idea?

The last line I could place a breakpoint on (in the node_modules/superagent/lib/node/index.js):

`if ('string' != typeof url) url = format(url);`
  • the value of the variable url is a string, looks like a valid url
  • format() is in the 'url' module as urlFormat()

Error:

TypeError: str.charCodeAt is not a function
    at encodeAuth (url.js:929:17)
    at Request.Url.format (url.js:543:12)
    at urlFormat (url.js:535:63)
    at new Request (/develop/sl/node_modules/superagent/lib/node/index.js:129:11)
    at request (/develop/sl/node_modules/superagent/lib/request.js:26:12)
    at Request.use (/develop/sl/node_modules/superagent/lib/request-base.js:65:3)
    ...

Update: It is probably not related to V8 engine as it is still the v4 instead of the new v5.

$ node -pe 'this.process.versions'
{ http_parser: '2.6.2',
  node: '5.10.1',
  v8: '4.6.85.31',
  uv: '1.8.0',
  zlib: '1.2.8',
  ares: '1.10.1-DEV',
  icu: '56.1',
  modules: '47',
  openssl: '1.0.2g' }
Arsenite answered 27/4, 2016 at 15:17 Comment(5)
It is highly unlikely this is a node.js issue. That error probably means str is not what it is supposed to be (e.g. not a string). This could be an issue with some module not being entirely compatible with newer versions of node.js or could just be a bug in your code that, for some reason, is now visible. This will require your own debugging to see what str is at that point and how it got that way.Walkerwalkietalkie
Thanks, I'll double check it. The problem is that I can't step into with debug to check whats actually happening there ...Arsenite
Any JS code can be debugged. If there are async operations involved, it just requires setting breakpoints in the right places and running to those rather than single stepping through.Walkerwalkietalkie
It doesn't look async to me. Why is that there is no path to urlFormat, Request.Url and encodeAuth lines in the error stack? I guess there is a mismatch with the url module, node is probably using a different one.Arsenite
I got the same error while hitting an API from Angular on Node, I just came across some other post in which it is suggested to state the response type while hitting the HTTP request prevents the application from throwing this error. Like this - let output = this.http.get(this.url, { responseType: 'text' });Isolating

© 2022 - 2024 — McMap. All rights reserved.