Skip to content

PlatformTest import fails with cookie 2: undeclared dependency in FakeResponse #3467

Description

@ueberBrot

Describe the bug

I reproduced this in a fresh project using the latest Ts.ED release, 8.40.2, and cookie 2.0.1. All resolved Ts.ED framework packages are 8.40.2; the logger packages are 8.0.5.

Importing PlatformTest from @tsed/platform-http/testing fails before any tests or server setup run:

SyntaxError: The requested module 'cookie' does not provide an export named 'default'

FakeResponse.ts default-imports cookie and calls cookie.serialize(). Both are incompatible with cookie 2.

However, @tsed/platform-http does not declare cookie as a dependency or peer dependency. Its test helpers depend on the cookie version available in the application. Installing cookie 1.1.1 makes the same import succeed.

To Reproduce

Using Node 22.23.2 and Bun 1.4.2, run:

mkdir tsed-cookie-repro
cd tsed-cookie-repro

bun add --ignore-scripts --exact @tsed/platform-http@8.40.2 cookie@2.0.1

node --input-type=module -e "import { PlatformTest } from '@tsed/platform-http/testing'; console.log('PlatformTest imported:', typeof PlatformTest)"

The command exits with code 1:

node_modules/@tsed/platform-http/lib/esm/testing/FakeResponse.js:2
import cookie from "cookie";
       ^^^^^^
SyntaxError: The requested module 'cookie' does not provide an export named 'default'

Then install cookie 1.1.1 and repeat the import:

bun add --ignore-scripts --exact cookie@1.1.1

node --input-type=module -e "import { PlatformTest } from '@tsed/platform-http/testing'; console.log('PlatformTest imported:', typeof PlatformTest)"

This exits with code 0:

PlatformTest imported: function

These commands were tested in a fresh directory. No application code, database, or test runner is needed.

Expected behavior

Importing PlatformTest should work without the application having to supply an undeclared cookie dependency.

@tsed/platform-http should declare the cookie version its test helpers require, so upgrading the application’s own cookie dependency does not break the import.

Code snippets

import { PlatformTest } from "@tsed/platform-http/testing";

console.log("PlatformTest imported:", typeof PlatformTest);

Repository URL example

No response

OS

Ubuntu 26.04.1 LTS

Node version

22.23.2

Library version

@tsed/platform-http 8.40.2; cookie 2.0.1

Additional context

Cookie 2 introduced two changes that affect FakeResponse:

These changes are documented in the cookie 2.0.0 release notes.

Changing only the default import to a namespace import still leaves FakeResponse.cookie() failing with:

TypeError: cookie.serialize is not a function

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions