Skip to content

With a reviver, a module that has no default export fails with "Unsupported type" (structuredClone of a module namespace) #38

Description

@Shinrai

Problem

When a reviver is passed and the loaded module has no default export, wisp falls back to the module namespace object and passes it through structuredClone. A module namespace can't be structured-cloned, so the call throws. That error gets caught and reported as wisp's generic "Unsupported type" error, which hides the real cause and fails a load that should either work or give a clear error.

Found while porting the suite to vitest-runner (#37). The new tests pin the current behaviour.

Fix

Decide the contract for a module without a default export when a reviver is given:

  • either apply the reviver to a plain-object copy of the namespace's own enumerable properties ({ ...ns }) rather than structuredClone(ns),
  • or throw a clear error saying a reviver needs a JSON value or a default export.

Then update the pinned test to the intended behaviour, for both wisp and wispSync where applicable.

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

    area: coreTouches core library / runtime source codepriority: lowMinor issue or improvement that can be deferred without impactstatus: implementedBuilt and deployed, but not yet fully tested/verifiedtype: bugSomething is broken or not behaving as expected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions