tsImport() fails with ERR_MODULE_NOT_FOUND on Node 24 when a CommonJS-context .ts file imports an ESM dependency
Author: ryanbonialCreated May 22, 2026Updated Aug 5, 2026
Labelsbugpending triage
Acknowledgements
- I read the documentation and searched existing issues to avoid duplicates
- I understand this is a bug tracker and anything other than a proven bug will be closed
- I understand this is a free project and relies on community contributions
- I read and understood the Contribution guide
Minimal reproduction URL
https://github.com/ryanbonial/tsx-pkg-utils-node24-repro
Problem & expected behavior (under 200 words)
What happened: tsImport() throws ERR_MODULE_NOT_FOUND on Node 24 when a CommonJS-context .ts file imports a dependency from an ESM package. Works on Node 22.
What I expected: Same behavior on Node 24 as Node 22 (load succeeds).
Matrix with [email protected]: Node 22.13.1 ✓, 22.18.0 ✓, 24.12.0 ✗, 24.15.0 ✗.
Stack trace:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../esm-fixture/dist/index.js?namespace=1779473031813' imported from .../config/package.config.ts?namespace=1779473031813
at finalizeResolution (node:internal/modules/esm/resolve:274:11)
at moduleResolve (node:internal/modules/esm/resolve:864:10)
at defaultResolve (node:internal/modules/esm/resolve:990:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
at nextStep (node:internal/modules/customization_hooks:189:26)
at resolveBaseSync (.../tsx/dist/register-D_B8UL5H.mjs:2:8642)
at resolveDirectorySync (.../tsx/dist/register-D_B8UL5H.mjs:2:9781)
at resolveTsPathsSync (.../tsx/dist/register-D_B8UL5H.mjs:2:11014)
at resolve2 (.../tsx/dist/register-D_B8UL5H.mjs:2:12901) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///.../esm-fixture/dist/index.js%3Fnamespace=1779473031813'
}The repro mirrors @sanity/pkg-utils's loadConfig(): tsImport(pathToFileURL(configFile).toString(), import.meta.url) where configFile is a CJS-context package.config.ts doing import { defineConfig } from '@sanity/pkg-utils'.
Bugs are expected to be fixed by those affected by it
- I'm interested in working on this issue
Compensating engineering work will speed up resolution and support the project
- I'm willing to offer $10 for financial support
Source: privatenumber/tsx