script.js:3 Uncaught TypeError: Localbase is not a constructor
neomewilson opened this issue · 2 comments
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.
Can you place the code on codesandbox so we can test it correctly the behaviour?
If you still have this problem, please make another issue