Skip to content

Add esm module support #2023

@vladshcherbin

Description

@vladshcherbin

Hey 👋

Node 12+ supports esm modules, Node 10 end of life is in April which means we can stop using babel, bundlers, etc in node 🥳
Package maintainers are starting to publish new package versions with only esm modules support, e.g. sindresorhus with 1k+ packages is going this road (article).

It would be great to see esm module support in objection. Currently some imports/exports don't work:

// works
import { Model } from 'objection'`
console.log(Model)

// doesn't work - throws error
import { snakeCaseMappers } from 'objection'

// works - current workaround
import objection from 'objection'
console.log(objection.snakeCaseMappers)

Produced error (node v15.12.0):

SyntaxError: Named export 'snakeCaseMappers' not found. The requested module 'objection' is a CommonJS module,
which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'objection';
const { snakeCaseMappers } = pkg;

Since 3.0 is coming with knex 0.95 support, maybe this can be also added in major release.

Thank you 🤗

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions