samuk190 / localbase

A Firebase-Style Database ... Offline!
636 stars 84 forks source link

script.js:3 Uncaught TypeError: Localbase is not a constructor #58

Closed neomewilson closed 3 months ago

neomewilson commented 2 years ago

If I use the following code in the HTML file, it works perfect without any errors. Records are added to the localbase database without any issues. I won't use it this way because that's a security hole exposing database code in my HTML for all to see. If I put it in a script.js file with the same code with the exception of using the import statement you'll see below I get the Uncaught Type Error: Localbase is not a constructor.

`import * as Localbase from 'https://unpkg.com/localbase/dist/localbase.min.js'

let db = new Localbase('db')

let buttonAdd = document.getElementById('Add')

buttonAdd.addEventListener('click', Add)

function Add() {
let selectedType = document.getElementById('Type').value

db.collection('thoughts').add({ id: Date.now(), title: document.getElementById('Title').value, context: document.getElementById('Context').value, type: selectedType }) }`

Please let me know what I should change or if this is never going to work.

samuk190 commented 3 months ago

Can you place the code on codesandbox so we can test it correctly the behaviour?

samuk190 commented 3 months ago

If you still have this problem, please make another issue