Skip to content

perry-codegen: classes from compilePackages have no instance methods/fields #482

Closed

Description

@proggeramlug

Repro (v0.5.576)

```bash
mkdir -p test/node_modules/handcl
cat > test/package.json <<EOJ
{ "name": "t", "type": "module", "perry": { "compilePackages": ["handcl"] } }
EOJ
cat > test/node_modules/handcl/package.json <<EOJ
{ "name": "handcl", "main": "index.js", "type": "module" }
EOJ
cat > test/node_modules/handcl/index.js <<EOJ
class Foo {
constructor() { this.name = "Foo"; }
add(a, b) { return a + b; }
}
export { Foo };
EOJ
cat > test/r.ts <<EOJ
import { Foo } from 'handcl';
const f = new Foo();
console.log('name:', f.name, 'add:', typeof f.add);
EOJ
perry test/r.ts -o test/out && test/out
```

Observed

```
name: undefined add: undefined
```

Expected

```
name: Foo add: function
```

Notes

  • Reproduces with both .js and .ts source in node_modules.
  • Reproduces with `class Foo {}` declaration AND `var Foo = class {}` expression assignment.
  • The same class definition in a project-local `.ts` file (not in compilePackages) works correctly.
  • `new Foo()` succeeds (returns an object), but the resulting instance has neither own properties (`name`) nor prototype methods (`add`).

Why it matters

Blocks #421 (hono) at the deeper dispatch level. Hono's `RegExpRouter`'s `add()` / `buildAllMatchers()` methods are unreachable, so route registration silently no-ops and `app.fetch()` returns a default 404-shape Response. Likely also blocks #420 (drizzle) at any point where drizzle's class instances are constructed and methods invoked.

Likely root cause

Perry-codegen's per-class method registration (`perry_method_`) and dispatch (`HANDLE_METHOD_DISPATCH` / `js_register_class_method`) needs to fire for classes whose source module was discovered via the `compilePackages` resolver. Most stdlib + project-local class registration paths run during `compile_module_entry`, but the cross-package import resolver might short-circuit some of the wiring.

Workaround

None at user level. Only fix is to land in perry-codegen.

Activity

  1. added 2 commits that reference this issue on May 8, 2026
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 regression

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions