Skip to content

mailosaur isn't ESM compatible in runtime #86

@romansp

Description

@romansp

Updated to 11.0.2 but seems like #84 is still an issue. operation files are missing the same ESM/CommonJS compatibility as main entry file. Or maybe it's not needed at all if there's a separate esm build?

#85 seemed to fix tsc compilation but we're now seeing issues in runtime.

We use mailosaur in e2e tests with playwright and vite so our actual tsconfig is "module": "esnext" and "moduleResolution": "bundler". But it doesn't work with "module": "NodeNext" either.

➜  mailosaur-esm-issue git:(main) ✗ pnpm run check-and-run

> check-and-run
> tsc && node ./dist/index.js

file:///Users/roman/Documents/dev/mailosaur-esm-issue/node_modules/.pnpm/mailosaur@11.0.2_@types+node@24.10.13/node_modules/mailosaur/esm/operations/analysis.js:52
module.exports = Analysis;
^

ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/roman/Documents/dev/mailosaur-esm-issue/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/roman/Documents/dev/mailosaur-esm-issue/node_modules/.pnpm/mailosaur@11.0.2_@types+node@24.10.13/node_modules/mailosaur/esm/operations/analysis.js:52:1
    at ModuleJob.run (node:internal/modules/esm/module_job:413:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:660:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.13.0

minimal repro: https://github.com/romansp/mailosaur-esm-issue

  1. Clone
  2. Execute pnpm install
  3. Execute pnpm run check-and-run. this will compile via tsc and run with node

Node.js version: v24.13.0

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