Skip to content

Sample 34 test breaks with superjson 2.2.3 due to exact JSON matching #15834

@mag123c

Description

@mag123c

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Summary
Sample 34 (sample/34-using-esm-packages) E2E test fails with superjson 2.2.3

Image

Error Message
expected '{"jsonString":"{"json":{"big":"10"},"meta":{"values":{"big":["bigint"]}}}"}'
got '{"jsonString":"{"json":{"big":"10"},"meta":{"values":{"big":["bigint"]},"v":1}}"}'

superjson 2.2.3 was published to npm on Oct 22, 2025 (06:20 UTC), and CI tests started failing immediately after. The package added a "v": 1 field to the meta object for backward compatibility

Context

  • Sample 34 demonstrates how to import and use ESM-only packages in a CommonJS
    NestJS project (Node 18.8+)
  • Uses superjson as an example ESM package
  • superjson 2.2.3 added a "v": 1 field to the meta object (PR A way to create own console commands #311)
  • Test uses exact JSON string matching, making it fragile to format changes

Minimum reproduction code

https://github.com/nestjs/nest/tree/master/sample/34-using-esm-packages

Steps to reproduce

  1. cd sample/34-using-esm-packages
  2. npm install (installs superjson 2.2.3 due to "superjson": "2.x")
  3. npm run test:e2e
  4. Test fails

Expected behavior

  • ESM package is successfully imported
  • ESM package functions correctly
  • NOT verify superjson's internal serialization format

Better approach example

.expect((res) => {
  const result = JSON.parse(res.body.jsonString);
  expect(result.json.big).toBe('10');
  expect(result.meta.values.big).toEqual(['bigint']);
});

NestJS version

11.1.7

Packages versions

{
  "@nestjs/common": "11.x",
  "@nestjs/core": "11.x",
  "@nestjs/platform-express": "11.x",
  "superjson": "2.x"
}

Node.js version

18.8+

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Purpose of Sample 34 is demonstrates importing ESM-only packages in CommonJS NestJS projects using Node 18.8+'s --experimental-vm-modules flag with dynamic imports.

Related

Proposed solutions

  1. Fix test to be format-agnostic (recommended)
  2. Pin superjson to 2.2.2
  3. Update expected output to include "v": 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions