Skip to content

check script uses require() in ESM package; fails with ERR_REQUIRE_ESM on Node 20+ #105

@kjonescertinia

Description

@kjonescertinia

Problem

npm/package.json declares "type": "module" but the check script still uses CommonJS require:

```json
"check": "node -e 'require("./dist/src/index.js").check()'",
```

On Node 20+ this throws ERR_REQUIRE_ESM immediately — npm run check fails before parsing any files.

Likely uncaught so far because nothing in CI invokes check; manifests only when an end user runs the documented smoke-check command after npm install.

Fix

Use import() (works in both CJS and ESM contexts, no --input-type needed):

```json
"check": "node -e 'import("./dist/src/index.js").then(m => m.check())'",
```

Context

Surfaced when modernising vf-parser (apex-dev-tools/vf-parser#8) by mirroring this script line-for-line. Codex flagged it there; fixed in apex-dev-tools/vf-parser@af98f97. Same one-line fix applies here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions