godaddy / kubernetes-client

Simplified Kubernetes API client for Node.js.
MIT License
960 stars 192 forks source link

Typescript Help: Client is not a constructor #734

Open stoked10 opened 2 years ago

stoked10 commented 2 years ago

I pulled the code directly from the typescript example in the README:

import * as ApiClient from 'kubernetes-client';

const Client = ApiClient.Client1_13;
const client = new Client({ version: '1.13' });

My only difference is loading the kubeconfig from the cluster:

const kubeconfig = new KubeConfig();
kubeconfig.loadFromCluster();
const backend = new Request({ kubeconfig });
return new ApiClient.Client1_13({ backend, version: '1.13' });

When I run this typescript gives me an error:

Error initializing client: TypeError: Client is not a constructor

I tried everything I could think of and searched the googles and couldn't come up with anything, any help would be greatly appreciated!

node: 16.15.0 typescript: 4.6.2

stoked10 commented 2 years ago

I finally figured out a workaround, it's not the greatest though. I basically had to cut the typings out of it:

import pkg from 'kubernetes-client/lib/index';

const kubeconfig = new KubeConfig();
kubeconfig.loadFromCluster();
const backend = new Request({ kubeconfig });

const { Client1_13 } = pkg;
return new Client1_13({ backend, version: '1.13' });