Skip to content

Regression in loading file-type under Windows #16179

@schulzjo-tng

Description

@schulzjo-tng

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The FileTypeValidator runs into (and catches) an exception when trying to load file-type under Windows. This is because require.resolve("file-type") returns an absolute (Windows) path, which one must not plug into loadEsm (see e.g. nodejs/node#31710).

Minimum reproduction code

https://github.com/schulzjo-tng/file-type-windows-issue-repro

Steps to reproduce

  1. On Windows, run npm i and npm start in the linked repository.

If you do not have a Windows machine, take a look at this CI run:

Run npm start
  
> [email protected] start
> node index.cjs
node:internal/modules/esm/load:195
    throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
          ^
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:195:11)
    at defaultLoadSync (node:internal/modules/esm/load:142:3)
    at #loadAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:795:12)
    at #loadSync (node:internal/modules/esm/loader:815:49)
    at ModuleLoader.load (node:internal/modules/esm/loader:780:26)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:526:31)
    at #getOrCreateModuleJobAfterResolve (node:internal/modules/esm/loader:571:36)
    at afterResolve (node:internal/modules/esm/loader:624:52)
    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:630:12)
    at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:649:32) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
Node.js v24.12.0
Error: Process completed with exit code 1.

Expected behavior

The file-type package should be loaded correctly on Windows.

NestJS version

11.1.11

Packages versions

Only @nestjs/common is relevant, which is on version 11.1.11.

Node.js version

24.11.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

This is a regression from #16077.

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