square / square-nodejs-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find name 'Blob' when running typescript complier

mtwichel opened this issue · comments

When compiling my typescript project after installing this package (using tsc), it gave me the following errors:

stacktrace
node_modules/square/dist/apiResponse.d.ts:14:20 - error TS2304: Cannot find name 'Blob'.

14     body: string | Blob | NodeJS.ReadableStream;
                      ~~~~

node_modules/square/dist/errors/apiError.d.ts:17:20 - error TS2304: Cannot find name 'Blob'.

17     body: string | Blob | NodeJS.ReadableStream;
                      ~~~~

node_modules/square/dist/errors/responseValidationError.d.ts:13:20 - error TS2304: Cannot find name 'Blob'.

13     body: string | Blob | NodeJS.ReadableStream;
                      ~~~~

node_modules/square/dist/fileWrapper.d.ts:5:11 - error TS2304: Cannot find name 'Blob'.

5     file: Blob | import('stream').Readable;
            ~~~~

node_modules/square/dist/fileWrapper.d.ts:7:23 - error TS2304: Cannot find name 'Blob'.

7     constructor(file: Blob | import('stream').Readable, options?: FileWrapperOptions | undefined);
                        ~~~~

node_modules/square/dist/http/httpResponse.d.ts:9:20 - error TS2304: Cannot find name 'Blob'.

9     body: string | Blob | NodeJS.ReadableStream;
                     ~~~~

node_modules/square/dist/http/requestBuilder.d.ts:27:19 - error TS2304: Cannot find name 'AbortSignal'.

27     abortSignal?: AbortSignal;
                     ~~~~~~~~~~~

node_modules/square/dist/http/requestBuilder.d.ts:70:96 - error TS2304: Cannot find name 'Blob'.

70     callAsStream(requestOptions?: RequestOptions): Promise<ApiResponse<NodeJS.ReadableStream | Blob>>;
                                                                                                  ~~~~

node_modules/square/dist/http/requestBuilder.d.ts:128:96 - error TS2304: Cannot find name 'Blob'.

128     callAsStream(requestOptions?: RequestOptions): Promise<ApiResponse<NodeJS.ReadableStream | Blob>>;
                                                                                                   ~~~~

node_modules/square/dist/http/requestBuilder.d.ts:136:59 - error TS2304: Cannot find name 'Blob'.

136 export declare function convertToStream(content: string | Blob | NodeJS.ReadableStream): Blob | NodeJS.ReadableStream;
                                                              ~~~~

node_modules/square/dist/http/requestBuilder.d.ts:136:90 - error TS2304: Cannot find name 'Blob'.

136 export declare function convertToStream(content: string | Blob | NodeJS.ReadableStream): Blob | NodeJS.ReadableStream;

After some Googling, I found (in this issue) that I needed to add "dom" to complierOptions.lib array in my tsconfig.json.

I don't think this is an error in the package, but it may be smart to add it to the readme or at least have it documented in an issue in case someone else has the same issue 😄

Hello there, is your project browser based?

Nope running on Firebase Cloud Functions

Since this is now documented in this issue and the fix exists outside the SDK, I am closing this issue.