Skip to content
Back

Fetch Appwrite Types - How to use

  • 0
  • General
  • Tools
  • Web
  • Databases
Jamieyes
18 Nov, 2024, 21:16

I am trying to use fetch-appwrite-types (https://www.npmjs.com/package/fetch-appwrite-types?activeTab=readme) to dynamically generate my database collection types in my NextJs/Typescript project. I am getting the following error when i run my generate-types.mjs file via node:

TypeScript
TypeError: Invalid URL
    at new URL (node:internal/url:787:36)
    at Databases.list (file:///Users/jamiedoe/Developer/Projects/sales-psychology-saas-web-app/node_modules/fetch-appwrite-types/node_modules/node-appwrite/dist/services/databases.mjs:27:17)
    at FetchNewTypes (file:///Users/jamiedoe/Developer/Projects/sales-psychology-saas-web-app/node_modules/fetch-appwrite-types/dist/main.js:52:49)
    at async file:///Users/jamiedoe/Developer/Projects/sales-psychology-saas-web-app/generate-types.mjs:3:1 {
  code: 'ERR_INVALID_URL',
  input: 'undefined/databases'
}

This is my generate-types.mjs file:

TypeScript
const { FetchNewTypes } = await import("fetch-appwrite-types/dist/main.js");

await FetchNewTypes({
  includeDBName: true,
  outDir: "./src/types",
  outFileName: "appwriteTypes",
});

Any help would be much apprecited!

TL;DR
Developers encountering errors while trying to use the fetch-appwrite-types package to generate database collection types. Error related to an Invalid URL issue. The problem may be due to missing or incorrectly spelled environment variables. Make sure to check the documentation for the library.
Kenny
18 Nov, 2024, 21:20

I'm pretty sure you're missing an environment variable or it's spelt incorrectly. Have you read the documentation for this library?

https://www.npmjs.com/package/fetch-appwrite-types?activeTab=readme#quick-usage

Jamieyes
18 Nov, 2024, 21:23

Thanks for your quick response!

I have the environment vars correctly configured, they are within my .env.local file... don't know if that would have an effect. The documentation isn't all that clear, i've triple checked the docs to no avail! 😅

Jamieyes
18 Nov, 2024, 21:24

Hahaha looks like it was due to the .env.local 😂

Jamieyes
18 Nov, 2024, 21:25

Working as intended now i beleive

Kenny
18 Nov, 2024, 21:28

:P Whoops, yea, that's a bummer. It is a package made and maintained by a community member, I'm sure they'd be happy if you left an issue for that so they could address it

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