Skip to content

Fix/file type peer dependency #15364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Yasir-Rafique
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

The FileTypeValidator dynamically imports the file-type package using loadEsm. This approach can lead to loading the wrong version of file-type if another package (like jimp) installs a different version that gets hoisted, resulting in inconsistent or incorrect file validation results.

This was reported in #15270, where developers were encountering issues like:
Validation failed (current file type is application/octet-stream, expected type is ...)

Issue Number: 15270

What is the new behavior?

Replaced dynamic import using loadEsm with a direct static import:
import { fileTypeFromBuffer } from 'file-type';

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This fix ensures more predictable and stable validation behavior in file uploads by removing reliance on hoisted or mismatched file-type versions. It improves compatibility and aligns the package with modern best practices for peer dependency handling.

@coveralls
Copy link

coveralls commented Jul 2, 2025

Pull Request Test Coverage Report for Build 05c47aac-d54b-49df-839c-d5f1aa8a4d4e

Details

  • 12 of 14 (85.71%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.003%) to 88.915%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/pipes/file/file-type.validator.ts 12 14 85.71%
Totals Coverage Status
Change from base Build bc91b2b9-9bd0-4dac-a3ac-a0d262be1578: -0.003%
Covered Lines: 7203
Relevant Lines: 8101

💛 - Coveralls

@Yasir-Rafique
Copy link
Author

All tests and lint checks are now passing ✅. However, the benchmark check is currently failing due to an external issue:

The Codechecks.io service used for benchmarking appears to be offline for maintenance, returning a 503 Service Unavailable response

This error is unrelated to the changes in this PR and seems to stem from the benchmarking service itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants