You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT: require('./mod') from inside a class method returns a non-callable value #668
Under perry compile, a require('./helper') call inside a class method body returns something whose method properties throw TypeError: value is not a function when called. Node + Bun handle the same source (treated as CJS-compatible) and return a real module object.
require() was used in @perryts/redis to break a module-import cycle between connection.ts and pipeline.ts. Workaround: convert to a top-level static ES import — ESM cycles are legal as long as the cross-imports are referenced inside function bodies (which they are here).
// repro.tsclassC{load(): unknown{returnrequire('./helper');}}constc=newC();constm=c.load()asany;console.log('typeof m: ',typeofm,' has greet:',m&&typeofm.greet);if(m&&typeofm.greet==='function')console.log(m.greet('world'));
$ perry compile /tmp/repro.ts -o /tmp/repro && /tmp/repro
TypeError: value is not a function
at <anonymous>
exit=1
Bun output (correct):
typeof m: object has greet: function
hello, world
Node + tsx (correct):
typeof m: object has greet: function
hello, world
Impact
Any driver/library that uses inline require() to break import cycles is broken under AOT. The fix on the caller side is straightforward (static ESM import) but is a silent runtime failure rather than a compile error, so it's hard to discover without running.
Suggested behavior
Either lower require(literalPath) to an ESM-equivalent static module reference at compile time, or fail at compile with a clear "CJS require is not supported under perry compile — use static import" message.
Activity
fix(hir,codegen): #667 #668 #672 — AOT fixes for __dirname, require()…
fix(hir): #925 — append replacement hints to unimplemented-API errors (…
feat(compile): compile user .js/.cjs natively; support require() (#668)
feat(compile): compile user .js/.cjs natively; support require() (#668)…
fix(compile): const x = require('./user-module') binds undefined (#1721…
feat(hir): ambient require in compiled compilePackages modules (#5389 …