godaddy / kubernetes-client

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

Browser compatibility: make swagger-client not dependent on fs #337

Open cfellin1 opened 5 years ago

cfellin1 commented 5 years ago

fs is currently called in the swagger client constructor: https://github.com/godaddy/kubernetes-client/blob/master/lib/swagger-client.js#L106

This causes errors in browser and makes it very difficult to construct a browser-friendly swagger client.

silasbw commented 5 years ago

Ahh, yeah, yuck. Would love to hear suggestions / get help on this one.

abhishiv commented 5 years ago

Hey @cfellin1, do you think that configuring webpack to use browserfs provided fs module fix this for your usecase?

https://github.com/jvilk/BrowserFS#using-with-browserify-and-webpack

pastudan commented 5 years ago

This is because the client tries to load the swagger.json.gz file from disk -- I think it might be possible to use standard require statements here, based on the version requested? We might want to not gzip them in that case. Possibly we could allow importing only the specific versions, like import Client from 'kubernetes-client/1.15' for example to help reduce the bundle size?

For now, I got a little further by load the spec from the client, which skips the fs operations.

const client = new Client()
await client.loadSpec()