Back

Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL

  • 0
  • Web
Avidev-creator
4 Apr, 2024, 15:57

I have created a .env file which looks like this --

VITE_APP_APPWRITE_URL = "https://cloud.appwrite.io/v1" VITE_APPWRITE_PROJECT_ID = "660xxxxxxxxxx9" VITE_APPWRITE_DATABASE_ID = "66xxxxxxxxxxxxxx6" VITE_APPWRITE_COLLECTION_ID = "66xxxxxxxxxxxxxx6" VITE_APPWRITE_BUCKET_ID = "66xxxxxxxxxxxxxxxxx2"

I have created a conf.js file where i basically created an object named conf and have all these values as keys -

const conf = { appwriteUrl: String(import.meta.env.VITE_APPWRITE_URL), appwriteProjectId: String(import.meta.env.VITE_PROJECT_ID), appwriteDatabaseId: String(import.meta.env.VITE_DATABASE_ID), appwriteCollectionId: String(import.meta.env.VITE_COLLECTION_ID), appwriteBucketId: String(import.meta.env.VITE_BUCKET_ID), };

export default conf;

As soon as i am trying to use this i am getting bellow error --

appwrite.js?v=6408dfe6:916 Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL at Account.<anonymous> (appwrite.js?v=6408dfe6:916:19) at Generator.next (<anonymous>) at appwrite.js?v=6408dfe6:503:67 at new Promise (<anonymous>) at __awaiter (appwrite.js?v=6408dfe6:485:10) at Account.get (appwrite.js?v=6408dfe6:913:12) at AuthService.getCurrentUser (auth.js:42:33) at App.jsx:13:8 at commitHookEffectListMount (chunk-T7VP4UGM.js?v=6408dfe6:16904:34) at commitPassiveMountOnFiber (chunk-T7VP4UGM.js?v=6408dfe6:18152:19)

The error is arriving when i am using --

export class AuthService { client = new Client(); account; constructor() { this.client .setEndpoint(conf.appwriteUrl) .setProject(conf.appwriteProjectId); this.account = new Account(this.client); }.....

TL;DR
Developers are getting a TypeError due to an invalid URL construction in their code. The error arises when trying to use appwrite.js and constructor. Check the conf.js file for correct values and ensure valid URLs are being used.
Avidev-creator
4 Apr, 2024, 15:59

Please helppppp

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more