Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'startsWith' of undefined #998

Closed
2 tasks done
cesargdm opened this issue Dec 16, 2019 · 11 comments
Closed
2 tasks done

Cannot read property 'startsWith' of undefined #998

cesargdm opened this issue Dec 16, 2019 · 11 comments
Labels
bug Something does not work as it should ✭ help wanted ✭

Comments

@cesargdm
Copy link

Describe the bug

  • Node.js version: v10.15.3
  • OS & version: macOS 10.15.1
  • Got: version 10.0.4

When trying to make a POST request to https://www.google.com I get an error using version 10.0.4 but getting back to version 9.0.4 returns a correct response.

Actual behavior

When trying to make a POST request to https://www.google.com I get the error

{ GotError: Cannot read property 'startsWith' of undefined
    at get (/Users/cesargdm/Development/Sites/fucesa-cloud/node_modules/got/dist/source/request-as-event-emitter.js:200:27)
    at urlToOptions (internal/url.js:1259:28)
    at Object.request (https.js:271:15)
    at Object.request (/usr/local/lib/node_modules/serverless/node_modules/agent-base/patch-core.js:23:20)
    at get (/Users/cesargdm/Development/Sites/fucesa-cloud/node_modules/got/dist/source/request-as-event-emitter.js:197:43) code: undefined, name: 'RequestError' }

Expected behavior

Don't throw error,

Code to reproduce

got.post('https://www.google.com')

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

I cannot reproduce: https://runkit.com/szmarczak/5df73664584fba001a4bfa10

@sindresorhus
Copy link
Owner

@cesargdm It would be helpful if you could submit a pull request with a failing tests.

@jacobjenks
Copy link

jacobjenks commented Dec 18, 2019

I'm also having this problem. It seems related to this issue nodejs/node#26198

@szmarczak szmarczak added bug Something does not work as it should ✭ help wanted ✭ labels Dec 18, 2019
@szmarczak
Copy link
Collaborator

Fix: https://github.com/nodejs/node/pull/26226/files

@koderyoda
Copy link

const response = await got("https://www.google.com");

The hello world of got is failing with with this error, using 10.5.5 with nodejs 10.16.0 on MacOS 10.15.2:

GotError: Cannot read property 'startsWith' of undefined\n at get (/Users/anon/WebstormProjects/artha/node_modules/got/dist/source/request-as-event-emitter.js:199:27)\n at urlToOptions (internal/url.js:1259:28)\n at Object.request (https.js:279:15)\n at Object.<anonymous> (/Users/anon/WebstormProjects/artha/node_modules/agent-base/patch-core.js:23:20)\n at get (/Users/anon/WebstormProjects/artha/node_modules/got/dist/source/request-as-event-emitter.js:196:65)

@szmarczak
Copy link
Collaborator

@ApoorvaNs It's a bug in Node.js 10. The issue has been fixed >= Node.js 12.

@koderyoda
Copy link

@ApoorvaNs It's a bug in Node.js 10. The issue has been fixed >= Node.js 12.

Thanks much @szmarczak, will try node 12.

@freewil
Copy link

freewil commented Mar 24, 2020

nodejs/node#26226 was backported to v10.x via nodejs/node#32446. It should be available >= 10.20.0 which is unreleased as of writing this message.

@artem-karpenko
Copy link

For all those coming here because of this somewhat ephemeral issue with got
The culprit is not a node version, but agent-base implementation visible in original stacktrace as well. It incorrectly clones URL which results in a later fail in internal node request code. The fix in Nodejs referenced above only fixes problem as in it provides a failsafe validation for URL - the request will still work incorrectly since url.hostname will not be present.

The real issue is that even though agent-base has been updated to fix the problem, proxy-agent (which uses it) was not - see TooTallNate/node-proxy-agent#51. Solution for my case was to use npm-force-resolutions to override transitive dependency over agent-base in my project.

@vnenkpet
Copy link

@artem-karpenko Can you please explain what exactly have you done to fix this?

@vnenkpet
Copy link

It seems like Google Cloud Function's nodejs10 runtime updated it's version and now we can't deploy any service using got as they all fail, which is a pretty big issue for us. I don't understand this.

lfdebrux added a commit to alphagov/accessible-autocomplete that referenced this issue Jun 18, 2020
We are seeing issues similar to
sindresorhus/got#998, apparently it is fixed
in Node 12.
lfdebrux added a commit to alphagov/accessible-autocomplete that referenced this issue Jun 18, 2020
We are seeing issues similar to
sindresorhus/got#998, apparently it is fixed
in Node 12.
lfdebrux added a commit to alphagov/accessible-autocomplete that referenced this issue Jun 18, 2020
We are seeing issues similar to
sindresorhus/got#998, apparently it is fixed
in Node 12.
lfdebrux added a commit to alphagov/accessible-autocomplete that referenced this issue Jun 18, 2020
We are seeing issues similar to
sindresorhus/got#998, apparently it is fixed
in Node 12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should ✭ help wanted ✭
Projects
None yet
Development

No branches or pull requests

8 participants