A problem with Astro, Astro-db, TypeScript and NodeJS

36 views Asked by At

I am doing a project for class using Astro, as I also need a database I tried to connect with Astro-DB but when I run "npm run dev" I get the error.

I use the most recent version of Astro and v18.20 of NodeJS

Here is the TypeScript of the tables

import { reference } from 'astro:content';
import { defineDb, defineTable, column } from 'astro:db';

// https://astro.build/db/config

const Teacher = defineTable({
  columns:{
    id : column.text({ primaryKey : true }),
    dni : column.text({ unique : true }),
    name : column.text({ unique : true }),
    departmentID : column.text({ references : () => Department.columns.id })
  }
})

const Department = defineTable({
  columns:{
    id : column.text({ primaryKey : true }),
    location : column.text({ unique : true }),
  }
})

const Student = defineTable({
  columns:{
    id : column.text({ primaryKey : true }),
    dni : column.text({ unique : true }),
    nia : column.text({ unique : true }),
    name : column.text({ unique : true }),
  }
})

const Class = defineTable({
  columns:{
    id : column.text({ primaryKey : true }),
    location : column.text({ unique : true }),
    teacherID : column.text({ references : () => Teacher.columns.id })
  }
})

const Subject = defineTable({
  columns:{
    id : column.text({ primaryKey : true }),
    location : column.text({ unique : true }),
    classId : column.text({references : () => Class.columns.id}),
  }
})

const Class_Student = defineTable ({
  columns : {
    classId : column.text({ references : () => Class.columns.id}),
    studenId : column.text({ references : () => Student.columns.id}),
  }
})

const Teacher_Student = defineTable({
  columns: {
    teacherId: column.text({ references : () => Teacher.columns.id }),
    studentId: column.text({ references : () => Student.columns.id }),
  },
})

export default defineDb({
  tables: {}
});

And here the error

Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'astro:'
  Stack trace:
    at new NodeError (node:internal/errors:405:5)
    at defaultLoad (node:internal/modules/esm/load:99:3)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:288:22)
    at #createModuleJob (node:internal/modules/esm/loader:312:17)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:251:17)

I tried updating to NodeJS v21.17 but it still gave me the same error.

0

There are 0 answers