I am trying to add Objection.js to my project (using ES6 "type": "module"
), and getting this error which points to ./models/user.js
:
import { Model } from "objection";
^^^^^
SyntaxError: The requested module 'objection' does not provide an export named 'Model'
Using the following code:
./methods.js
import User from "./models/user.js";
async function getInfo(idnum) {
const someUser = await User.query().findById(idnum);
return someUser;
}
./models/user.js
import db from "../connection.js";
import { Model } from "objection";
Model.knex(db);
class User extends Model {
static get tableName() {
return "users";
}
}
export default User;
./connection.js
const environment = process.env.NODE_ENV || "development";
import knexfile from "../knexfile.js";
const connection = knexfile[environment];
import knex from "knex";
const db = knex(connection);
export default db;
UPDATE
The creator of Objection.js said import { Model } from "objection"
should work.
What am I doing wrong?