Note: The code that used to be here now lives in the proxy-agents
monorepo.
tootallnate / node-socks-proxy-agent Goto Github PK
View Code? Open in Web Editor NEWA SOCKS (v4/v5) proxy `http.Agent` implementation for HTTP and HTTPS
A SOCKS (v4/v5) proxy `http.Agent` implementation for HTTP and HTTPS
Note: The code that used to be here now lives in the proxy-agents
monorepo.
https.request accepts arguments like (url, options, cb) since node version 10.9
but agent-base does not
it replace https.request with a patch in a patch-core.js
which set options.port to 443 to fix an earlier problem
but the patch only accept (options, cb)
Hi there,
Recently I've detected an issue on node-socks-proxy-agent and same for https proxy agent.
When you import socks-proxy-agent in a package.json from a git submodule (when you use it as a workspace), it generates some issues, most probably it is caused due to certificate imports.
Please review postinstalls or imports in code, it seems somewhere is a mispath.
In "socks-proxy-agent" version 6.1.1 found that "lookup = true" for protocol "socks5", while "lookup = false" for "socks" and "socks5h" (file /node_modules/socks-proxy-agent/dist/agent.js, lines 56-74):
switch (opts.protocol.replace(':', '')) {
case 'socks4':
lookup = true;
// pass through
case 'socks4a':
type = 4;
break;
case 'socks5':
lookup = true;
// pass through
case 'socks': // no version specified, default to 5h
case 'socks5h':
type = 5;
break;
default:
throw new TypeError(`A "socks" protocol must be specified! Got: ${opts.protocol}`);
}
Protocol RFC1928 for SOCKS5 specifies: "This new protocol extends the SOCKS Version 4 model to include UDP".
It means that DNS can be resolve on SOCKS5 proxy side and no need to lookup it locally at a client.
To fix it just replace the code above with the following:
switch (opts.protocol.replace(':', '')) {
case 'socks4':
lookup = true;
// pass through
case 'socks4a':
type = 4;
break;
case 'socks': // no version specified, default to 5h
case 'socks5':
case 'socks5h':
type = 5;
break;
default:
throw new TypeError(`A "socks" protocol must be specified! Got: ${opts.protocol}`);
}
I'm using with request v2.85.0.
Putting domain name when creating the instance will get following error:
node_modules/socks/build/common/helpers.js:30
throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsProxy, options);
^
If creating using the IP address such as "socks://127.0.0.1", it's OK.
I want to use this library in typescript, but there is no definition file. I searched in this repository and DefinitelyTyped.
Could you please add d.ts
?
At Node.js 16:
DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
at Object.connect (_tls_wrap.js:1629:15)
at SocksProxyAgent.<anonymous> (/home/node/app/node_modules/socks-proxy-agent/src/agent.ts:175:15)
at Generator.next (<anonymous>)
at fulfilled (/home/node/app/node_modules/socks-proxy-agent/dist/agent.js:5:58)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
Pointing to
node-socks-proxy-agent/src/agent.ts
Line 175 in d1cb60f
Hi,
I can't seem to find any working example anywhere with it working with Undici (the newest and faster HTTP Client from official NodeJS).
I've however seen multiple users inquiring about it, including on Stackoverflow without any reply so far.
From March 2021: http://5.9.10.113/66459770/how-to-use-authenticated-proxies-with-undici
Hello, I couldn't find set custom headers tutorial in document. I'm using below code for this purpose but I don't know it is true.
Could you answer the correct way of set custom headers on socks proxy agent please?
const proxy = {
proxy: '137.77.140.101:1085',
userAgent: 'Mozilla/5.0 (Linux; Android 11; LM-Q720) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.105 Mobile Safari/537.36',
};
const options = url.parse('socks://' + proxy.proxy);
options.headers = {
'User-Agent': proxy.userAgent,
};
const agent = new SocksProxyAgent(options);
ws = new WebSocket('wss://domain.com', { agent: agent, handshakeTimeout: 10000 });
Hi, I have pool of proxies and want to count their usages for determinate how many times one proxy was used for connect, could I do it without forking and adding this functional?
I'm already try to scan response after each fetch, but do not see anything about it :(
I need it for know that keep-alive works.
ty
Just a week ago I installed Windows 21H2 (build 19044.1415). And the other day I needed to install Node.js (16.13.1, npm 8.1.2). After installation, npm refuses to start:
C:\Program Files\nodejs>npm
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\agent.js:114:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:5:33)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:161:25)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\agent.js:114:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:5:33)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:161:25)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
C:\Program Files\nodejs>
Original problematic folder here:
In hearts, I deleted the problematic file: https://stackoverflow.com/a/70552439/8175291
CD /D "C:\Program Files\nodejs\node_modules\npm\node_modules"
RMDIR /S /Q "%CD%\socks-proxy-agent\dist\"
npm --global --force install [email protected]
node --trace-deprecation socks-proxy-agent
Although the npm worked, however, it became impossible to install any other module ("node install --save --force libxmljs socks-proxy-agent osmosis", i was trying this). I suspect it is because of these actions.
2022-01-02T16_09_26_173Z-debug-0.log
Please help, I'm stumped.
When I add the options below to the request
module, I get an error TypeError: A "socks" protocol must be specified! Got: undefined
. What's the correct way to use it with request
?
var SocksProxyAgent = require('socks-proxy-agent');
...
agentClass: SocksProxyAgent,
agentOptions: {
socksHost: 'localhost',
socksPost: 9050,
},
node version: v16.3.0
old working code (5.0.0)
agent: new SocksProxyAgent('socks5://127.0.0.1:9050');
error:
(Use `node --trace-deprecation ...` to show where the warning was created)
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
Error: write EPROTO 139806041069504:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
errno: -71,
code: 'EPROTO',
syscall: 'write'
}
after using 5.0.0 it works again.
It's possible to give userId
or username
https://github.com/TooTallNate/node-socks-proxy-agent/blob/master/src/index.ts#L82 but if you give username
it doesn't get used. username
should be used if it's given since it's used by the standard URL object.
Can you push latest version (with authentication support) to npm?
I'm getting a build failure
./node_modules/socks-proxy-agent/dist/agent.js
Cannot find module: 'dns'. Make sure this package is installed.
I see this import but it is not listed as a dependency. Any ideas?
const dns_1 = __importDefault(require("dns"));
I have an issue with https.get
used in mailjet
always trying to connect to localhost
when called with a string as argument (the url). I traced down the bug to agent-base
version <4.0 when options
is tested instead of _options
.
TL;DR
In socks-proxy-agent
, the recent dependency to agent-base
version ^4.1.0
seem OK in the master, but not in npm:
{ name: 'socks-proxy-agent',
description: 'A SOCKS proxy `http.Agent` implementation for HTTP and HTTPS',
'dist-tags': { latest: '3.0.0' },
versions:
[ '0.0.1',
...
'3.0.0' ],
...
dependencies: { 'agent-base': '^4.0.1', socks: '^1.1.10' },
devDependencies: { mocha: '^3.4.2', 'raw-body': '^2.2.0', socksv5: '0.0.6' },
...
Could you update the npm version to current? (master was updated on jun 27, while npm version is from jun 13, despite the same version number)
Thanks!
Just wanted to tell, you left your nord account here: https://github.com/TooTallNate/node-socks-proxy-agent/blob/master/nordvpn.ts#L33_L37
want i connect to wss, it's throw this error;
var WebSocket = require('ws');
var SocksProxyAgent = require('socks-proxy-agent');
// SOCKS proxy to connect to
var proxy = process.env.socks_proxy || 'socks://127.0.0.1:50984';
console.log('using proxy server %j', proxy);
// WebSocket endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'wss://api.huobi.pro/ws';
console.log('attempting to connect to WebSocket %j', endpoint);
// create an instance of the SocksProxyAgent class with the proxy server information
var agent = new SocksProxyAgent(proxy);
// initiate the WebSocket connection
var socket = new WebSocket(endpoint, { agent: agent });
socket.on('open', function () {
console.log('"open" event!');
// socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});
Uncaught TypeError: Cannot read property 'socket' of undefined
fixed in: #18
Hello my code snippet is
const newman = require('newman');
const SocksProxyAgent = require('socks-proxy-agent');
const requestAgent = new SocksProxyAgent({ host: '0.0.0.0', port: '8090' });
const pathtocheck = '/zapApiPostmanCollection.json';
console.log(pathtocheck);
newman.run({
collection: pathtocheck,
requestAgents: {
http: requestAgent, // agent used for HTTP requests
https: requestAgent, // agent used for HTTPS requests
},
insecure:'true',
reporters: 'cli'
},function (err) {
if (err) { throw err; }
console.log('collection run complete!');
I am running this inside docker and proxy at 0.0.0.0:8090 is accessible - PFA
But i am getting Socket Closed Error
Rainbow socket fails to handle ECONNREFUSE or any error emit by the underlying socket connection.
This was fixed in the lastest version 1.4 bencevans/node-rainbowsocks@e6e98b3#diff-168726dbe96b3ce427e7fedce31bb0bcR27.
Socks-proxy-agent fail to bubble it, and I can't handle it in the proxy-agent modules and in the top http layer.
TS keeps telling me this error:
import https from 'https';
import { SocksProxyAgent } from 'socks-proxy-agent';
const info = {
host: 'br41.nordvpn.com',
userId: '[email protected]',
password: 'abcdef12345124'
};
const agent = new SocksProxyAgent(info);
https.get('https://jsonip.org', { agent }, (res) => {
console.log(res.headers);
res.pipe(process.stdout);
});
Error:
Type 'SocksProxyAgent' is not assignable to type 'boolean | Agent'.
Property 'freeSockets' is missing in type 'SocksProxyAgent' but required in type 'Agent'.ts(2322)
TS version: Version 3.9.5
Socks-proxy-agent leaks memory on every creation.
Here is example code that leaks memory very fast
const SocksProxyAgent = require('socks-proxy-agent')
function makeAgent() {
setTimeout(makeAgent, 5)
return new SocksProxyAgent.SocksProxyAgent({
hostname: 'google.com'
})
}
makeAgent()
Please add handling of error in tls and soket connection:
Client network socket disconnected before secure TLS connection was established
Thank you
is there any way to enable 'keepAlive: true' to keep connection alive with socks5 proxy server? so I can reuse active socket to get better response times instead of closing connection after every request
it works fine with: https://github.com/mattcg/socks5-https-client but it's not maintained anymore (library doesn't work with newest nodejs version)
I recently updated socks-proxy-agent and it stopped working because instead of opts.hostname || opts.host
it just uses opts.host
now (diff)
I tried use new URL()
, but in your code
Object.assign({}, opts)
not working correctly with newest features. I fixed it in my code with cycle, like this
const { URL } = require('url')
const SocksProxyAgent = require('socks-proxy-agent')
let proxy = new URL('https://...')
let props = {}
for (let i in proxy) {
props[i] = proxy[i]
}
proxy = props
let proxyAgent = new SocksProxyAgent(proxy)
What i need to do in next time?
Hi 👋
First of all, thanks for your work!
We're using it every day in order to access private services during our development using an SSH connection with dynamic port forwarding to a bastion.
It is now possible to override http.globalAgent
. It will help us remove the agent from our client and other dependencies will then be able call those private services as well.
I tried to override http.globalAgent
giving a new SocksProxyAgent
instead but it throws the following error:
_http_client.js:142
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
^
TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "undefined"
at new ClientRequest (_http_client.js:142:11)
at request (http.js:44:10)
at Object.get (http.js:48:15)
at Object.<anonymous> (/Users/charly/Work/pro/MMB/starship/packages/stargate-backend/test.js:11:6)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:822:10)
at internal/main/run_main_module.js:17:11
❌ Here is the code I used:
const http = require('http')
const SocksProxyAgent = require('socks-proxy-agent')
http.globalAgent = new SocksProxyAgent(process.env.HTTP_PROXY)
http.get('private url', console.log)
✅ It is only working when used as an agent in the request options:
const http = require('http')
const SocksProxyAgent = require('socks-proxy-agent')
http.get('private url', {
agent: new SocksProxyAgent(process.env.HTTP_PROXY),
}, console.log)
node version: v12.2.0
What did I do wrong? Do you get why it is not working when used as a globalAgent
?
Is it possible to make it work?
I'm quite keen on implementing a solution and then opening a PR if you give me a solution 😅
Thanks in advance for your help! 🙏
Hello, I tried to connect to proxy with node-socks-proxy-agent.
My config:
new SocksProxyAgent({
host: '127.0.0.1',
port: 1080,
protocol: 'socks:',
auth: 'username:password'
});
And I getting error: Socks5 Authentication failed
I see logs in my proxy-server:
error after reading 7 bytes in 0 seconds: could not access user ""'s records in the system password file: no system error
Hey @TooTallNate ,
I'm depending on a fix from this library that you merged a couple of days ago and a fix in the socks
library that was published in version 2.3.1. Would you consider bumping the dependency and re-publishing the package?
Thanks!
The examples uses url parsing
function parse(urlStr: string): UrlWithStringQuery;
UrlWithStringQuery inherits URL
The problem is it returns the type URL which has following interface
interface Url {
auth: string | null;
hash: string | null;
host: string | null;
hostname: string | null;
href: string;
path: string | null;
pathname: string | null;
protocol: string | null;
search: string | null;
slashes: boolean | null;
port: string | null;
query: string | null | ParsedUrlQuery;
}
there is no agent here. It means typescript will complain and I think it is a valid complain too.
Is there anything we can do to fix this.
The typescript branch also uses Agent (agent-base) which seems to be incompatible with http.Agent.
Please let me know if there is easy way to get rid of this error.
Error: Invalid SOCKS proxy details were provided.
at Object.validateSocksClientOptions (/myAwesomeProject/node_modules/socks/src/common/helpers.ts:40:11)
at Function.createConnection (/myAwesomeProject/node_modules/socks/src/client/socksclient.ts:95:5)
at onlookup (/myAwesomeProject/node_modules/socks-proxy-agent/index.js:118:17)
at SocksProxyAgent.connect [as callback] (/myAwesomeProject/node_modules/socks-proxy-agent/index.js:143:5)
at ProxyAgent.connect (/myAwesomeProject/node_modules/proxy-agent/index.js:196:11)
at /myAwesomeProject/node_modules/es6-promisify/dist/promisify.js:75:41
at new Promise (<anonymous>)
at ProxyAgent.callback (/myAwesomeProject/node_modules/es6-promisify/dist/promisify.js:54:20)
at ProxyAgent.addRequest (/myAwesomeProject/node_modules/agent-base/index.js:161:26)
at new ClientRequest (_http_client.js:261:16)
at Object.request (http.js:42:10)
at Needle.send_request (/myAwesomeProject/node_modules/needle/lib/needle.js:478:26)
at next (/myAwesomeProject/node_modules/needle/lib/needle.js:371:10)
at Needle.start (/myAwesomeProject/node_modules/needle/lib/needle.js:374:17)
at Function.module.exports.request (/myAwesomeProject/node_modules/needle/lib/needle.js:794:56)
at /myAwesomeProject/node_modules/needle/lib/needle.js:753:22
at new Promise (<anonymous>)
at module.exports (/myAwesomeProject/node_modules/needle/lib/needle.js:752:12)
at Page.needle (/myAwesomeProject/src/scraper/base.js:106:20)
at Page.needle [as request] (/myAwesomeProject/src/scraper/base.js:75:33)
at Page.request [as open] (/myAwesomeProject/src/scraper/base.js:52:31)
os: Ubuntu 18.04 via WLS on Windows 10.1803
node: 11.10.1
proxy-agent: ^3.0.3,
Need update socks
to latest v2.3.2
Hi all,
I am following the example code but cant seem to get the HTML back when requesting through this module...
I get a ERRCONREFUSED error :(
I am getting SOCKS proxy addresses from this website: https://hidemyna.me/en/proxy-list/?type=45&anon=34#list
var url = require('url');
var https = require('https');
var SocksProxyAgent = require('socks-proxy-agent');
// SOCKS proxy to connect to
var proxy = process.env.socks_proxy || 'socks://177.223.106.232';
console.log('using proxy server %j', proxy);
// HTTP endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'https://geenstijl.nl';
console.log('attempting to GET %j', endpoint);
var opts = url.parse(endpoint);
// create an instance of the `SocksProxyAgent` class with the proxy server information
// NOTE: the `true` second argument! Means to use TLS encryption on the socket
var agent = new SocksProxyAgent(proxy, true);
opts.agent = agent;
https.get(opts, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
Hey there,
thanks a lot for the agents - they're really useful. 👍
I ran into an issue with socks proxy sockets not being closed properly,
which expressed itself in the node process not shutting down in time.
The following is an example of a "faulty" socks proxy (it's actually a http proxy):
const agent = new ProxyAgent('socks5://163.172.173.187:3000')
agent.timeout = 1 * 1000 // socket timeout, relevant for socks
The above will correctly timeout the connection after 1 second (agent-base functionality),
but the underlying socket used by socks
remains open for the default timeout of 30s.
The fix is very simple (I confirmed it's working), we just have to pass the timeout
property to the socks client (Socks docs).
I'd love to present you a finished PR for this small fix, but unfortunately I'm somehow unable to find a way to use the existing timeout
property from the agent-base Class. 😅
Would be great if you could have a quick look, if you could tell me how to re-use the existing timeout property I'm happy to submit a PR.
Thanks!
The sample websocket code is not working.
$ nodejs wssample.js
"open" event!
And waiting forever. Here is a stripped strace log:
socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 11
connect(11, {sa_family=AF_INET, sin_port=htons(9050), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
...
getsockopt(11, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
...
write(11, "\5\2\0\2", 4) = 4
...
read(11, "\5\0", 65536) = 2
...
write(11, "\5\1\0\3\22echo.websocket.org\0P", 25) = 25
...
read(11, "\5\0\0\1\0\0\0\0\0\0", 65536) = 10
...
write(11, "GET / HTTP/1.1\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nHost: echo.websocket.org\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: MTMtMTQ0MzQ4OTA0NTMyOA==\r\nSec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n\r\n", 227) = 227
...
read(11, "HTTP/1.1 101 Web Socket Protocol Handshake\r\nConnection: Upgrade\r\nDate: Tue, 29 Sep 2015 01:10:44 GMT\r\nSec-WebSocket-Accept: Skuj8JwFPQlBBFU/wO93Q9JB6Sk=\r\nServer: Kaazing Gateway\r\nUpgrade: websocket\r\n\r\n", 65536) = 201
setsockopt(11, SOL_TCP, TCP_NODELAY, [1], 4) = 0
...
write(1, "\"open\" event!\n", 14) = 14
write(11, "\201\213)\223\3\312A\366o\246F\263t\245[\377g", 17) = 17
...
read(11, "\201\vhello world", 65536) = 13
....
And here waiting forever.
As you can see, the response received but message event was not fired.
http sample works.
agent-base should updated
my shadowsocks server is:
Congratulations, Shadowsocks-go server install completed!
Your Server IP : 120.77.99.104
Your Server Port : 9999
Your Password : ***
Your Encryption Method: aes-256-cfb
i try options like this when using socks-proxy-agent to connect shadowsocks server:
const agent = new SocksProxyAgent({
hostname: '120.77.99.104',
port: 9999,
protocol: 'socks5',
password: '***',
custom_auth_method: 'aes-256-cfb',
});
axios.options.httpAgent = agent
i got a error after send a request:
Error: Received invalid Socks5 initial handshake (invalid socks version)
Is there some way to ignore a self signed certificate?
With the https agent you can set rejectUnauthorized: false
but can't find how to ignore it with this proxy agent
Basically we just have to allow passing an array of objects instead of a single object to the constructor and then call createConnectionChain instead of createConnection
.
I'm already working on it and would like to make a Pull Request when I'm done, if that's okay with you.
But there are some issues I need help with:
1. Starting with node 15 / npm 7
, npm install
fails:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: [email protected]
npm ERR! node_modules/eslint-plugin-import
npm ERR! dev eslint-plugin-import@"2.16.0" from the root project
npm ERR! peer eslint-plugin-import@"^2.14.0" from [email protected]
npm ERR! node_modules/eslint-config-airbnb
npm ERR! dev eslint-config-airbnb@"17.1.0" from the root project
npm ERR! 1 more (eslint-import-resolver-typescript)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer eslint-plugin-import@"^2.17.2" from [email protected]
npm ERR! node_modules/eslint-config-airbnb/node_modules/eslint-config-airbnb-base
npm ERR! eslint-config-airbnb-base@"^13.1.0" from [email protected]
npm ERR! node_modules/eslint-config-airbnb
npm ERR! dev eslint-config-airbnb@"17.1.0"node 6 / npm 3 from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/fedora/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/fedora/.npm/_logs/2021-01-30T20_34_16_949Z-debug.log
For now I've switched to node 6 / npm 3
, as this is the lowest supported version according to your package.json
With node 6 / npm 3
I just get this warning:
npm WARN [email protected] requires a peer of eslint-plugin-import@^2.17.2 but none was installed.
2. npm run test-lint
reports 23 errors (before I even made any code changed):
> [email protected] test-lint /home/fedora/Projects/GitClones/node-socks-proxy-agent
> eslint src --ext .js,.ts
=============
WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.
You may find that it works just fine, or you may not.
SUPPORTED TYPESCRIPT VERSIONS: ~3.2.1
YOUR TYPESCRIPT VERSION: 3.9.7
Please only submit bug reports when using the officially supported version.
=============
/home/fedora/Projects/GitClones/node-socks-proxy-agent/src/agent.ts
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-unresolved
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/named
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/extensions
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/order
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-self-import
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-cycle
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-useless-path-segments
8:40 error Unable to resolve path to module '.' import/no-unresolved
56:4 error Expected a 'break' statement before 'case' no-fallthrough
62:4 error Expected a 'break' statement before 'case' no-fallthrough
/home/fedora/Projects/GitClones/node-socks-proxy-agent/src/index.ts
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-cycle
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/extensions
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/order
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-self-import
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-unresolved
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-useless-path-segments
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-named-as-default
1:1 error Resolve error: /home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-import-resolver-typescript/index.js:32
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at tryRequire (/home/fedora/Projects/GitClones/node-socks-proxy-agent/node_modules/eslint-module-utils/resolve.js:51:10) import/no-named-as-default-member
4:30 error Unable to resolve path to module './agent' import/no-unresolved
12:1 error ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace
12:11 error 'createSocksProxyAgent' is already defined no-redeclare
24:14 error Multiple exports of name 'SocksProxyAgent' import/export
25:15 error Multiple exports of name 'SocksProxyAgent' import/export
✖ 23 problems (23 errors, 0 warnings)
npm ERR! Linux 5.8.18-100.fc31.x86_64
npm ERR! argv "/home/fedora/.nvm/versions/node/v6.17.1/bin/node" "/home/fedora/.nvm/versions/node/v6.17.1/bin/npm" "run" "test-lint"
npm ERR! node v6.17.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test-lint: `eslint src --ext .js,.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test-lint script 'eslint src --ext .js,.ts'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the socks-proxy-agent package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! eslint src --ext .js,.ts
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs socks-proxy-agent
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls socks-proxy-agent
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/fedora/Projects/GitClones/node-socks-proxy-agent/npm-debug.log
$ npm run test-lint
> [email protected] test-lint /home/fedora/Projects/GitClones/node-socks-proxy-agent
> eslint src --ext .js,.ts
Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.
/home/fedora/Projects/GitClones/node-socks-proxy-agent/src/agent.ts
1:1 error Definition for rule '@typescript-eslint/class-name-casing' was not found @typescript-eslint/class-name-casing
1:1 error Definition for rule '@typescript-eslint/interface-name-prefix' was not found @typescript-eslint/interface-name-prefix
1:1 error Definition for rule '@typescript-eslint/no-triple-slash-reference' was not found @typescript-eslint/no-triple-slash-reference
8:40 error Missing file extension "ts" for "." import/extensions
56:4 error Expected a 'break' statement before 'case' no-fallthrough
62:4 error Expected a 'break' statement before 'case' no-fallthrough
/home/fedora/Projects/GitClones/node-socks-proxy-agent/src/index.ts
1:1 error Definition for rule '@typescript-eslint/class-name-casing' was not found @typescript-eslint/class-name-casing
1:1 error Definition for rule '@typescript-eslint/interface-name-prefix' was not found @typescript-eslint/interface-name-prefix
1:1 error Definition for rule '@typescript-eslint/no-triple-slash-reference' was not found @typescript-eslint/no-triple-slash-reference
4:30 error Missing file extension "ts" for "./agent" import/extensions
12:1 error ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace
12:11 error 'createSocksProxyAgent' is already defined no-redeclare
✖ 12 problems (12 errors, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test-lint: `eslint src --ext .js,.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test-lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/fedora/.npm/_logs/2021-01-30T20_48_19_851Z-debug.log
3. After changing SocksProxyAgent
to support an array of proxies and turning opts from SocksProxyAgentOptions
into SocksProxyAgentOptions[]
, I get an error when super(opts);
is called:
src/agent.ts:143:9 - error TS2345: Argument of type 'SocksProxyAgentOptions[]' is not assignable to parameter of type 'AgentOptions | { (req: ClientRequest, opts: Re
questOptions, fn: AgentCallbackCallback): void; (req: ClientRequest, opts: RequestOptions): Duplex | ... 2 more ... | Promise<...>; } | undefined'.
Type 'SocksProxyAgentOptions[]' is not assignable to type '{ (req: ClientRequest, opts: RequestOptions, fn: AgentCallbackCallback): void; (req: ClientRequest, opts
: RequestOptions): Duplex | ... 2 more ... | Promise<...>; }'.
Type 'SocksProxyAgentOptions[]' provides no match for the signature '(req: ClientRequest, opts: RequestOptions, fn: AgentCallbackCallback): void'.
143 super(opts);
~~~~
Found 1 error.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/fedora/.npm/_logs/2021-01-30T21_01_44_169Z-debug.log
These are my changes so far.
Disclaimer: This is the first time I've touched TypeScript and it's still very confusing to me.
when i need to add my username & password to use my proxy server, what would i do? thank you!
I'm using the following code to connect & send requests through a TOR proxy on port 9050. I've verified the proxy is running, but the request doesn't seem to be going through.
export class Tor {
static get getProxy(): SocksProxyAgent {
const proxy = new SocksProxyAgent({
host: "socks5h://127.0.0.1:9050"
})
return proxy;
}
static async waitForProxy() {
let proxyActive = false;
let attempts = 1;
while (proxyActive == false) {
try {
await got("https://protonmailrmez3lotccipshtkleegetolb73fuirgj7r4o4vfu7ozyd.onion/", {
agent: {
http: Tor.getProxy,
https: Tor.getProxy
}
})
proxyActive = true;
} catch (err) {
console.log(err);
console.log("[Warning]".yellow, `Attempt ${attempts} to connect to resolve TOR failed.`);
await new Promise((resolve) => setTimeout(resolve, 2500));
attempts++;
}
}
}
}
I'm unsure if this problem is originating with the GOT http client, or from the proxy..
I have a Docker container running this image on my machine (it's a SOCKS proxy server) and I have exposed the needed ports needed for it to work. And when I run curl -x socks5://localhost:40000 https://ip.me
on my machine, the requests goes through fine and everything works. But when I try to send a request from node using the proxy agent, it doesn't work. Here is my code:
const fetch = require('node-fetch')
const { SocksProxyAgent } = require('socks-proxy-agent')
const req = await fetch(`https://google.com`, {
agent: new SocksProxyAgent(`socks5://localhost:40000`)
})
console.log(req.ok)
console.log(req.status)
Here is my error:
/home/______/______/node_modules/node-fetch/lib/index.js:1376
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://google.com/ failed, reason: Socket closed
at ClientRequest.<anonymous> (/home/______/______/node_modules/node-fetch/lib/index.js:1376:11)
at ClientRequest.emit (node:events:390:28)
at onerror (/home/______/______/node_modules/socks-proxy-agent/node_modules/agent-base/dist/src/index.js:117:21)
at callbackError (/home/______/______/node_modules/socks-proxy-agent/node_modules/agent-base/dist/src/index.js:136:17) {
type: 'system',
errno: undefined,
code: undefined
}
Node.js v17.0.0
I'm not sure why this is happening. Can anyone try to help?
From proxy-agent
, one should be able to pass the options object:
proxy_agent({
protocol: 'socks5',
host: '127.0.0.1',
port: 8182,
});
However, once it calls socks-proxy-agent
constructor then this block throws an exception at the default case since protocol does not end in :
.
The message is reported by tests:
SocksProxyAgent
constructor
✔ should throw an Error if no "proxy" argument is given
✔ should accept a "string" proxy argument
✔ should accept a `url.parse()` result object argument
"http" module
✔ should work against an HTTP endpoint
"https" module
(node:63516) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
(Use `node --trace-deprecation ...` to show where the warning was created)
✔ should work against an HTTPS endpoint
5 passing (27ms)
I've got the following exception when I try to fetch data from the pornhub api
FetchError: maximum redirect reached at: https://www.pornhub.com/webmasters/video_by_id?id=ph5c6a26be4c538&thumbsize=medium_hd
at ClientRequest.<anonymous> (/app/node_modules/node-fetch/lib/index.js:1498:15)
at ClientRequest.emit (events.js:210:5)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:585:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:17)
at TLSSocket.socketOnData (_http_client.js:454:22)
at TLSSocket.emit (events.js:210:5)
at addChunk (_stream_readable.js:325:12)
at readableAddChunk (_stream_readable.js:300:11)
at TLSSocket.Readable.push (_stream_readable.js:234:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23) {
message: 'maximum redirect reached at: https://www.pornhub.com/webmasters/video_by_id?id=ph5c6a26be4c538&thumbsize=medium_hd',
type: 'max-redirect'
}
Does anyone have an idea whats happening there? I've tried the same proxy within my browser and everything is working normal.
And yes, I've tested if I'm connected through the proxy …
I found I cannot resolve hostname into IP address.
Many program (eg. curl, wget) have a special proxy mode, resolve DNS through proxy.
Can I do same thing with this module?
Log:
Error: socket hang up
source-map-support.js:445
at TLSSocket.onHangUp (_tls_wrap.js:1135:19)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at TLSSocket.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
System:Window10
Node:10
Appropriate error handling should be added.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.