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
}
});

};
}
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.
2 Replies
kapa.ai
kapa.ai3w ago
Hi @Just Simeon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your question and the knowledge sources available, I don't have enough specific information to directly address the error you're encountering with Google Cloud Storage in a Nuxt application. However, I can provide some general guidance on error handling in Nuxt that might help you troubleshoot the issue: 1. Error Handling in Nuxt: Nuxt provides several ways to handle errors. In your case, you're seeing a 500 error, which typically indicates a server-side error. Nuxt has a built-in error handling system that you can leverage to get more information about the error. 2. Custom Error Page: You can create a custom error page to handle and display errors more gracefully. Create an error.vue file in your project's root directory to customize the error page. This can help you get more details about the error. Nuxt Error Handling Documentation (https://nuxt.com/docs/getting-started/error-handling#error-page) 3. Vue Error Handling: Nuxt also allows you to hook into Vue errors. You can use the vue:error hook in a Nuxt plugin to catch and handle errors globally. This might give you more insight into what's causing the error. Nuxt Vue Error Handling (https://nuxt.com/docs/getting-started/error-handling#vue-errors) 4. Debugging: To get more information about the error, you might want to add more detailed logging or use debugging tools. The Nuxt DevTools can be helpful for this purpose. 5. Server-side vs. Client-side: Make sure that your Google Cloud Storage operations are indeed running on the server-side as intended. The error message you're seeing might be related to how the code is being executed. 6. Nuxt Version: Ensure you're using a stable version of Nuxt. Some errors can be related to specific versions of the framework. If you continue to face issues, it would be helpful to create a minimal reproduction of the problem and share more details about your Nuxt configuration and environment. This would allow for a more specific diagnosis of the issue. Remember, when dealing with server-side operations in Nuxt, it's important to handle errors properly and provide fallback mechanisms for a better user experience. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@294593079812292609> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server