socks-proxy-agent missing dependencies

231 Views Asked by At

I am trying to use socks-proxy-agent as a React hook, but get compilation errors about not find these packages: net, dns and tls. These are not listed as dependencies on NPM and are not in socks-proxy-agent package.json.

Below is my code:

import { useState, useEffect } from 'react';
import axios from 'axios';
import SocksProxyAgent from 'socks-proxy-agent';

const useSocks5ProxyRequest = () => {
  const [data, setData] = useState(null);
  const [error, setError] = useState(null);
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    const fetchData = async () => {
      setLoading(true);

      try {
        // Create a new instance of axios with the SOCKS5 proxy agent
        const agent = new SocksProxyAgent('socks5://127.0.1.1:9050');
        const axiosInstance = axios.create({ httpAgent: agent, httpsAgent: agent });

        // Make your API request using the axios instance
        const response = await axiosInstance.get('https://httpbin.org/ip');
        setData(response.data);
      } catch (error) {
        setError(error);
      }

      setLoading(false);
    };

    fetchData();
  }, []);

  return { data, error, loading };
};

export default useSocks5ProxyRequest;

And here are the error lines:

Module not found: Error: Can't resolve 'net' in '/usr/src/app/node_modules/socks/build/client'
Module not found: Error: Can't resolve 'tls' in '/usr/src/app/node_modules/socks-proxy-agent/dist'
Module not found: Error: Can't resolve 'dns' in '/usr/src/app/node_modules/socks-proxy-agent/dist'

Anyone have thoughts on how to resolve?

Thanks

0

There are 0 best solutions below