Back

[SOLVED] Uncaught ReferenceError: ID is not defined

  • 0
  • Web
  • Storage
Fezuks
15 Mar, 2024, 19:29

Hi! In my SvelteKit project, I have the following appwrite.js file:

TypeScript
import { Client, Databases, Account, Storage } from "appwrite";

const client = new Client();
client
    .setEndpoint("https://cloud.appwrite.io/v1")
    .setProject("<my id>"); // Replace with your project ID

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

then in +page.svelte script i have (basically from tutorial):

TypeScript
import { storage } from "$lib/appwrite";
const upload = () => {
        const promise = storage.createFile(
            "files",
            ID.unique(),
            document.getElementById("uploader").files[0],
        );

        promise.then(
            function (response) {
                console.log(response); // Success
            },
            function (error) {
                console.log(error); // Failure
            },
        );
    };

But when i try to upload i get the following error: Uncaught ReferenceError: ID is not defined. Any ideas why? Probably I did something stupid

TL;DR
Developers were not importing the ID from the appwrite module which resulted in the error "Uncaught ReferenceError: ID is not defined." To fix this, they need to import the ID by adding `import { ID } from "appwrite"` or `import { ID } from "node-appwrite"`.
Kenny
15 Mar, 2024, 19:32

Looks like you're not importing ID from anywhere so it's undefined.

Kenny
15 Mar, 2024, 19:32

import { ID } from "appwrite" or import { ID } from "node-appwrite"

Fezuks
15 Mar, 2024, 19:41

Thank you very much!

Fezuks
15 Mar, 2024, 19:41

For some reason on the wbsite the ID isn't imported anywhere

Kenny
15 Mar, 2024, 19:50

[SOLVED] Uncaught ReferenceError: ID is not defined

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