Skip to content

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

Closed

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

Activity

  1. pullfrog commented on Jul 27, 2026

    @pullfrog
    Contributor
  2. ssalbdivad commented on Oct 1, 2026

    @ssalbdivad
    Member

    Good catch, thanks! Fixed in #1674, going out with 2.2.7.

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

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions