Skip to content

compiler(bun): lower import.meta.require() through synchronous compiled-module dispatch #9742

Description

@proggeramlug

Problem

Bun-target bundles with split require() calls emit import.meta.require("./chunk-….js"). The call is synchronous: it evaluates the selected chunk and returns its namespace immediately.

Perry currently treats require as an unknown import.meta member. Generic member lowering turns the callee into undefined, so the compiled program fails with TypeError: value is not a function; the module collector also does not discover that chunk.

This is a Bun bundle primitive, independent of any particular application.

Minimal repro

dep.js:

globalThis.loads = (globalThis.loads ?? 0) + 1;
export const answer = 42;

main.js:

const first = import.meta.require("./dep.js");
const second = import.meta["require"]("./dep.js");

console.log(first.answer, second.answer, globalThis.loads);
perry compile main.js --platform bun -o app
./app

Expected:

42 42 1

Acceptance criteria

  • Direct and computed-literal spellings lower to Perry's synchronous module-dispatch representation.
  • Relative paths and /$bunfs/root/… paths under --bunfs-root are discovered and compiled.
  • The call returns the module namespace synchronously and evaluates the target once.
  • A missing or non-statically-resolvable target produces the same bounded AOT diagnostic as synchronous require(expr).
  • Ordinary import.meta properties and user-defined/shadowed values keep their existing behavior.
  • An end-to-end compiled-binary regression covers both spellings.

Aliased native-addon discovery/distribution is separate from this issue (see #9606).

Activity

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

    bugConfirmed defect or regressionparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions