Good day,
I have a nextjs project that I have implemented a function for add/deleting files on google drive, I initially got this error while developing Type error: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'Iterable<any> | AsyncIterable<any>'
and solved it by manually assigning ReadableStream<Uint8Array>
as one of the expected interface inside the stream
library, everything worked fine & properly locally both dev
and build
but then when I try deploying the same project to vercel, during the build process I get this error
Failed to compile.
./config/serverUtils.ts:70:37
Type error: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'Iterable<any> | AsyncIterable<any>'.
68 | const media = {
69 | mimeType: file.type,//'application/octet-stream',
> 70 | body: Readable.from(fileBuffer),
| ^
71 | //body: fileBuffer
72 | };
73 |
Error: Command "npm run build" exited with 1
This is the full code producing the error ./config/serverUtils.ts
class GoogleDriveCRUD {
private oauth2client
private drive
constructor() {
this.oauth2client = new google.auth.GoogleAuth({
credentials: {
type: data.type,
project_id: data.project_id,
private_key_id: data.private_key_id,
private_key: data.private_key,//process.env.PRIVATE_KEY.replace(/\n/g, 'n'),
client_email: data.client_email,
client_id: data.client_id,
// auth_uri: data.auth_uri,
// token_uri: data.token_uri,
// auth_provider_x509_cert_url: data.auth_provider_x509_cert_url,
// client_x509_cert_url: data.client_x509_cert_url,
// universe_domain: data.universe_domain,
},
scopes: ["https://www.googleapis.com/auth/drive"],
});
//this.oauth2client.setCredentials({ refresh_token: refreshToken })
this.drive = google.drive({
version: "v3",
auth: this.oauth2client
})
}
//This function is used to add a file to GDrive
public async addFile(file: File, folderId: string | void) {
try {
const fileBuffer = file.stream();
const fileMetadata = {
name: file.name, // The name of the file to be uploaded
parents: folderId ? [folderId] : undefined, // The ID of the folder where the file should be uploaded
mimeType: file.type,
};
const media = {
mimeType: file.type,//'application/octet-stream',
body: Readable.from(fileBuffer),
//body: fileBuffer
};
const response = await this.drive.files.create({
requestBody: fileMetadata,
media: media,
fields: "id, imageMediaMetadata",
})
console.log("Response 1: ", response)
//console.log("Response 1: ", response.imageMediaMetadata)
return response.data
} catch (error) {
console.log(error)
}
}
//This function helps delete a file from GDrive
public async deleteFile(driveId: string) {
try {
const response = await this.drive.files.delete({
fileId: driveId
})
const res = await this.drive.files.get({
fileId: ""
})
console.log(response)
//console.log("Response: ", response.data)
} catch (error) {
console.log(error)
}
}
}
I have tried browsing for answers but have all being in vain, please I’m stranded and would really appreciate any form of help in solving this issue. Thanks!