NuxtN
Nuxt15mo ago
4 replies
Just Simeon

Weird Error without stacktrace

Hello, I am trying to upload a file using google's storage library. However whenever I call the method I get this error:
ERROR [nuxt] [request error] [unhandled] [500] Cannot read private member from an object whose class did not declare it

I am following google's docs to properly upload the file and can't spot something off. Here is my code:
import { ref } from 'vue';
import { Storage } from '@google-cloud/storage';

const storageInstance = ref<Storage | null>(null);

export function useGoogleStorage() {
    if (!import.meta.server) {
        throw new Error('useGoogleStorage can only be used on the server side.');
    }

    if (!storageInstance.value) {
        storageInstance.value = new Storage();
    }
    
    const uploadFile = async (bucketName: string, filePath: string, destination: string, contentType: string) => {
        if (!storageInstance.value) return;
        const bucket = storageInstance.value.bucket(bucketName);
        console.log('Uploading file to Google Cloud Storage:', destination);
        console.log('File path:', filePath);
        console.log('Content type:', contentType);
        await bucket.upload(filePath, {
            destination,
            metadata: {
                contentType
            }
        });
        
    };
}


the 3 console.logs are being execute properly and their output is also correct.
Was this page helpful?