Skip to content

Suggestion: Use InternalScope.scope instead of this.scope in static field arrow functions for Turbopack compatibility #1643

Description

@imsyf

Suggestion

scope.js:100-101 uses arrow functions in static class fields that reference this:

static scope = ((def, config = {}) => new InternalScope(def, config));
static module = ((def, config = {}) => this.scope(def, config).export());

Under Turbopack (Next.js 16 dev mode), the arrow function's lexical this binding is lost during transpilation, producing a module-level _this = void 0 and crashing with TypeError: Cannot read properties of undefined (reading 'scope').

Suggested fix — Convert to static method declarations (or use InternalScope.scope explicitly):

static scope(def, config = {}) {
    return new InternalScope(def, config);
}
static module(def, config = {}) {
    return InternalScope.scope(def, config).export();
}

This is a defensive workaround for a Turbopack dev-mode transpilation bug tracked at: vercel/next.js#96254

This is not a bug in arktype — the code is valid ES2022. Instance field arrow functions (lines 1795–1848) are transpiled correctly because Turbopack wraps them in IIFEs with proper _this capture. Only static field arrows are affected by the Turbopack issue.

Minimal reproduction

https://github.com/imsyf/arktype-turbopack-repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions