Skip to content

Support native ESM codegen #2244

@wemeetagain

Description

@wemeetagain

In ESM projects, where napi bindings are just one part of the repo, mixing ESM and CJS files can be a huge pain.
It would be nice for napi-rs to generate an index.js that is valid ESM.

At a bare minimum, this can be done by adding the following lines to the top of the generated file:

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

const __dirname = new URL('.', import.meta.url).pathname;

and updating the exports.

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