I feel this is something very basic, but I can't find the correct info. I'm including a javascript file in my html:
<script src="/js/client_db.js" type="text/javascript"></script>
In client_db.js I'm trying to include a class:
import { Socket } from './phoenix';
let socket = new Socket("/socket", { params: { userToken: "123" } })
socket.connect()
let db_channel = socket.channel("ledgers", {})
db_channel.join()
.receive("ok", resp => {
console.log("Joined successfully", resp)
clientDb(db_channel)
})
.receive("error", resp => { console.log("Unable to join", resp) })
.receive("timeout", () => console.log("Networking issue. Still waiting..."))
...
And in phoenix.js I have the class:
export class Socket {
...
However, in the browser console I get the error:
Uncaught SyntaxError: Cannot use import statement outside a module
Apparently, the correct way to solve this is to convert client_db.js to a module, but it is not at all clear how this is best done.