acacode / acacode/swagger-typescript-api
ReferenceError: File is not defined
- Lingua principale
- TypeScript
- Stelle
- 4.1k
- Fork
- 436
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
A generated client with Axios won't work as expected when executed from Node as you'll get the following error: `ReferenceError: File is not defined`.
The reason is that the following checks were added in https://github.com/acacode/swagger-typescript-api/pull/350 in response to https://github.com/acacode/swagger-typescript-api/issues/293:
https://github.com/acacode/swagger-typescript-api/blob/2b6db2346028fe6fb1f311bf5b1221a89837032e/templates/base/http-clients/axios-http-client.ejs#L87
[`File`](https://developer.mozilla.org/docs/Web/API/File) isn't supported on Node, and based on the description of this project, it seems like generated clients should be working from both Node and browsers, so we shouldn't reference `File` in here.
### Expected Behavior
Uploading a file / using [`multipart/form-data`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects) / using [`FormData`](https://developer.mozilla.org/docs/Web/API/FormData) should work as expected from browsers and Node environments.
### Actual Behavior
It works as expected within browsers but crashes with the following error on Node: `ReferenceError: File is not defined`.
### Potential Solution
[`File`](https://developer.mozilla.org/docs/Web/API/File) inherits from [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob), meaning that an instance of `File` will always be an instance of `Blob` as `Blob` constructor's `prototype` property appears in the prototype chain of `File`'s instance:
```typescript
new File(['foo'], 'foo.txt') instanceof Blob // true
```
It means that we should be able to strip the usage of `File` completely and only rely on `Blob`, which is supported by all environments.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.