Skip to content

Raise engines to the require(esm) floor #64

Closed as not planned
Closed as not planned

Description

@Shinrai

Problem

  • engines.node is >=16.0.0, but the CJS entry needs require(esm) (Node ^20.19 / ≥22.13), which the CJS file's own guard already enforces at runtime.

Tasks

  • package.json:
    • engines.node: ^20.19.0 || >=22.13.0 (Node 22.12.x warns when require() loads ESM)
  • Tests: pass --conditions=wisp-dev to vitest (resolve.conditions, ssr.resolve.conditions, test.nodeOptions) and to the node --test CJS run.

Related

Activity

  1. added
    type: enhancement
    priority: low
    area: core
    status: not started
    on Oct 25, 2026
  2. Shinrai commented on Oct 31, 2026

    @Shinrai
    ContributorAuthor

    Before this gets picked up: don't use the fire-and-forget (async () => { await import("../devcheck.mjs") })() block from the task list. It doesn't gate anything. Code that imports the package and calls it straight away runs before devcheck exits, from ESM and from CJS. Load it synchronously at the top of src/index.mjs instead:

    import { createRequire } from "node:module";
    
    try {
    	createRequire(import.meta.url)("../devcheck.mjs");
    } catch (error) {
    	if (error?.code !== "MODULE_NOT_FOUND") throw error; // devcheck.mjs is not published
    }

    Still no top-level await, so the CJS entry's require(esm) keeps working. Keep ../devcheck.mjs external in tsup. The dist test should look for the "../devcheck.mjs" specifier in dist/index.mjs, not for import(...).

    For the caller-resolution check: devcheck now runs while index.mjs is being evaluated, before any export can be called, so it still never shows up in a caller's stack. Worth confirming with those tests anyway.

    Working copy is fix-headers' src/index.mjs in CLDMV/fix-headers#165 (ships in 2.2.4).

  3. Shinrai commented on Oct 31, 2026

    @Shinrai
    ContributorAuthor

    Correction to my comment above: don't use that block either. The static import { createRequire } from "node:module" breaks browser bundles (esbuild and webpack fail the build, Vite's bundle throws at load). Use this instead:

    const nodeModule = typeof process === "undefined" ? undefined : process.getBuiltinModule?.("node:module");
    if (nodeModule) {
    	try {
    		nodeModule.createRequire(import.meta.url)("../devcheck.mjs");
    	} catch (error) {
    		if (error?.code !== "MODULE_NOT_FOUND") throw error; // devcheck.mjs is not published
    	}
    }

    Same synchronous gate, nothing for a bundler to resolve, and it skips itself in a browser. Checked against esbuild/webpack/Vite (browser and node), headless Chrome loading src/ directly, Node 20.19 / 22.12 / 26, ESM and CJS. The caller-resolution note still applies. Working copy is still CLDMV/fix-headers#165.

  4. Shinrai commented on Nov 1, 2026

    @Shinrai
    ContributorAuthor

    One more thing with the sync devcheck load: on Node 22.12.x, require() of devcheck.mjs prints an ExperimentalWarning (require of an ES module) on every source-checkout run. 20.19 and 22.13+ don't warn. Consumers of the published package never hit it since devcheck.mjs isn't shipped.

    When you adopt it, set engines.node to ^20.19.0 || >=22.13.0 (the CJS shim needs require(esm) anyway, so anything below 20.19 is already wrong) and keep the CI min_node_version off 22.12. fix-headers went to >=22.13.0 in CLDMV/fix-headers#165.

  5. changed the title [-]Add devcheck for the wisp-dev condition, and raise engines to the require(esm) floor[/-] [+]Raise engines to the require(esm) floor[/+] on Nov 1, 2026
  6. Shinrai commented on Nov 1, 2026

    @Shinrai
    ContributorAuthor

    Dropped the devcheck part, it's being removed from all the packages instead (the -dev condition already picks src or dist). Only the engines floor is left.

  7. added
    status: in progress
    and removed
    status: not started
    on Nov 1, 2026
  8. added
    status: implemented
    and removed
    status: in progress
    on Nov 1, 2026
  9. cldmv-bot commented on Nov 1, 2026

    @cldmv-bot
    Contributor

    Marked status: implemented — resolved by #65, merged into next. This issue closes automatically when that work ships to the default branch.

  10. added a commit that references this issue on Nov 2, 2026
  11. Shinrai commented on Nov 2, 2026

    @Shinrai
    ContributorAuthor

    Not doing this. wisp is meant to load JSON on older Node.js, so its engines stay at >=16.0.0 (#70). The require() guard names ^20.19.0 or >=22.13.0, and the 22.22.0 toolchain floor lives in devEngines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corepriority: lowstatus: implementedtype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions