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

compat(node/https): ClientRequest.setTimeout is not a function #17852

Closed
gamer0mega opened this issue Jul 28, 2022 · 14 comments
Closed

compat(node/https): ClientRequest.setTimeout is not a function #17852

gamer0mega opened this issue Jul 28, 2022 · 14 comments
Labels
bug Something isn't working correctly node compat

Comments

@gamer0mega
Copy link
Contributor

Describe the bug

ClientRequest.setTimeout in node/https erroring and saying that it is not a function, which is incompatible with node's https module and will break projects which use the compat mode.

Steps to Reproduce

  1. Create a file with contents
const https = require('https');
const request = https.request({method: 'GET', host: 'discord.com', path: 'https://discord.com/api/v10/gateway', headers: {"User-Agent": "DiscordBot"}});
request.setTimeout(10000);
request.end();
request.on('response', response => {
  response.on('data', data=>console.log(data.toString()));
  response.on('end', ()=>console.log('ok'));
});
  1. Run it using the Deno compat mode(it uses the std modules for node defaults)
>deno run -A --compat --unstable httpsTest.js
error: Uncaught (in promise) TypeError: request.setTimeout is not a function
    at Object.<anonymous> (file:///D:/usb/compatTest/httpsTest.js:3:9)
    at Object.<anonymous> (file:///D:/usb/compatTest/httpsTest.js:9:4)
    at Module._compile (https://deno.land/[email protected]/node/module.ts:260:36)
    at Object.Module._extensions..js (https://deno.land/[email protected]/node/module.ts:1332:10)
    at Module.load (https://deno.land/[email protected]/node/module.ts:239:34)
    at Function._load (https://deno.land/[email protected]/node/module.ts:558:14)
    at loadCjsModule ([deno:cli\compat\mod.rs:119:30]:3:22)

Expected behavior

>node httpsTest.js
{"url": "wss://gateway.discord.gg"}
ok

The code should return this, as on node.

Environment

  • OS: Windows 10
  • deno version: 1.24.0
  • std version: 0.149.0
@gamer0mega gamer0mega added bug Something isn't working correctly needs triage labels Jul 28, 2022
@gamer0mega
Copy link
Contributor Author

gamer0mega commented Jul 28, 2022

The exact same error occurs when using

import * as https from 'https://deno.land/[email protected]/node/https.ts';
const request = https.request({method: 'GET', host: 'discord.com', path: 'https://discord.com/api/v10/gateway', headers: {"User-Agent": "DiscordBot"}});
request.setTimeout(10000);
request.end();
request.on('response', response => {
  response.on('data', data=>console.log(data.toString()));
  response.on('end', ()=>console.log('ok'));
});

I get

>deno run -A --unstable httpsTest.js
error: Uncaught TypeError: request.setTimeout is not a function
request.setTimeout(10000);
        ^
    at file:///D:/usb/compatTest/httpsTest.js:3:9

@gamer0mega
Copy link
Contributor Author

gamer0mega commented Jul 28, 2022

Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.

@bartlomieju
Copy link
Member

Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.

Can you report it as a separate issue?

@gamer0mega
Copy link
Contributor Author

Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.

Can you report it as a separate issue?

I will, just noticed it.

@kt3k kt3k removed the needs triage label Jul 28, 2022
@luk3skyw4lker
Copy link

I'll take a stab at this one!

@iuioiua
Copy link
Contributor

iuioiua commented Sep 13, 2022

@luk3skyw4lker, are you still planning on tackling this one? Otherwise, I can give it a crack.

@luk3skyw4lker
Copy link

@iuioiua You can do it! I didn't manage to see it through

@lino-levan
Copy link
Contributor

Any updates @iuioiua? If not, I'd love to take a shot at this one.

@iuioiua
Copy link
Contributor

iuioiua commented Nov 5, 2022

I haven't started work on this. Be my guest! 🤙🏾

@kt3k
Copy link
Member

kt3k commented Jan 30, 2023

@gamer0mega Were you affected by this issue when you are using some actual npm modules in Deno?

@kt3k kt3k mentioned this issue Feb 21, 2023
14 tasks
@gamer0mega
Copy link
Contributor Author

@gamer0mega Were you affected by this issue when you are using some actual npm modules in Deno?

This issue is 6 months old and i had it when i tried to use an npm

@comunidadio
Copy link

Having the issue as well when using ethers.js

@barthuijgen
Copy link

barthuijgen commented Mar 10, 2023

Same issue trying to use npm:chrome-remote-interface reports not implemented: ClientRequest.setTimeout and Unexpected server response: 101. Not sure if the error would be solved by fixing the not implemented warning

note: this is on windows

Example code with the problem: https://gist.github.com/barthuijgen/37b19fad82b8f584477ef94052caa702

@bartlomieju
Copy link
Member

Fixed in d137501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants