Back

TypeError: Failed to construct 'URL': Invalid URL

  • 1
  • Web
Skull Crusher
19 Feb, 2025, 21:32

getting this error while everything seems fine please help me solve it

this is how my config file looks:

export const appwriteConfig = { projectId :import.meta.env.VITE_APPWRITE_PROJECT_ID, url :import.meta.env.VITE_APPWRITE_URL, databaseId :import.meta.env.VITE_APPWRITE_DATABASE_ID, storageId :import.meta.env.VITE_APPWRITE_STORAGE_ID, userCollectionId :import.meta.env.VITE_APPWRITE_USER_COLLECTION_ID, postCollectionId :import.meta.env.VITE_APPWRITE_POST_COLLECTION_ID, savesCollectionId :import.meta.env.VITE_APPWRITE_SAVES_COLLECTION_ID, };

export const client = new Client() .setProject('appwriteConfig.projectId') .setEndpoint('appwriteConfig.url');

export const account = new Account(client); export const databases = new Databases(client); export const storage = new Storage(client); export const avatars = new Avatars(client);

and this is my .env file looks

VITE_APPWRITE_PROJECT_ID = 6799f41bxxx5b7d20d5b VITE_APPWRITE_URL = https://cloud.appwrite.io/v1 VITE_APPWRITE_STORAGE_ID = 679a574e0xxxxxx060a VITE_APPWRITE_DATABASE_ID = 679a5xxxxxx0637725e VITE_APPWRITE_POST_COLLECTION_ID = 679a57dxxxxxxx5a1c26a
VITE_APPWRITE_USER_COLLECTION_ID = 679a582xxxxd5c4049a7 VITE_APPWRITE_SAVES_COLLECTION_ID = 6xxx584300xxx8fa7424

TL;DR
Developers were receiving a TypeError due to incorrect URL construction in the code. Ensure that the URL is not wrapped in quotes. The correct format for setting the project and endpoint should be: ```ts export const client = new Client() .setProject(appwriteConfig.projectId) .setEndpoint(appwriteConfig.url); ``` Additionally, the code for `signInAccount` is requested in the file `api.ts`.
Kenny
19 Feb, 2025, 21:48

Can you give the code for signInAccount in the file api.ts

Kenny
19 Feb, 2025, 21:50

Oh nevermind. The issue is you have your stuff wrapped in quotes. It should be.

TypeScript
export const client = new Client()
    .setProject(appwriteConfig.projectId)
    .setEndpoint(appwriteConfig.url);
Steven
19 Feb, 2025, 22:31

FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting).

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