diff --git a/.nvmrc b/.nvmrc index 8ce703082..3516580bb 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20.16.0 +20.17.0 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 143aa4da9..e3241c307 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2612,8 +2612,8 @@ packages: mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} - nan@2.18.0: - resolution: {integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==} + nan@2.20.0: + resolution: {integrity: sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==} nanoid@3.3.7: resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} @@ -6288,7 +6288,7 @@ snapshots: object-assign: 4.1.1 thenify-all: 1.6.0 - nan@2.18.0: {} + nan@2.20.0: {} nanoid@3.3.7: {} @@ -6296,7 +6296,7 @@ snapshots: node-pty@1.0.0: dependencies: - nan: 2.18.0 + nan: 2.20.0 node-releases@2.0.14: {} diff --git a/src/esm/hook/resolve.ts b/src/esm/hook/resolve.ts index 0702ea8e2..a92bf3df5 100644 --- a/src/esm/hook/resolve.ts +++ b/src/esm/hook/resolve.ts @@ -41,16 +41,29 @@ const getMissingPathFromNotFound = ( const isPackagePath = nodeError.message.match(/^Cannot find package '([^']+)'/); if (isPackagePath) { - const [, packageJsonPath] = isPackagePath; - const packageJsonUrl = pathToFileURL(packageJsonPath); + const [, packagePath] = isPackagePath; + if (!path.isAbsolute(packagePath)) { + return; + } + + const packageUrl = pathToFileURL(packagePath); - if (!packageJsonUrl.pathname.endsWith('/package.json')) { - packageJsonUrl.pathname += '/package.json'; + // Node v20.0.0 logs the package directory + // Slash check / works on Windows as well because it's a path URL + if (packageUrl.pathname.endsWith('/')) { + packageUrl.pathname += 'package.json'; } - const packageJson = readJsonFile(packageJsonUrl); - if (packageJson?.main) { - return new URL(packageJson.main, packageJsonUrl).toString(); + // Node v21+ logs the package package.json path + if (packageUrl.pathname.endsWith('/package.json')) { + // packageJsonUrl.pathname += '/package.json'; + const packageJson = readJsonFile(packageUrl); + if (packageJson?.main) { + return new URL(packageJson.main, packageUrl).toString(); + } + } else { + // Node v22.6.0 logs the entry path so we don't need to look it up from package.json + return packageUrl.toString(); } } }; diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 4d437cfae..24606f956 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -454,7 +454,7 @@ export default testSuite(async ({ describe }, { tsx, supports, version }: NodeAp * not match the required ones (3) */ if (!version.startsWith('18.')) { - test('resolve ts in main', async () => { + test('resolve ts in main', async ({ onTestFail }) => { await using fixture = await createFixture({ 'package.json': createPackageJson({ type: packageType }), 'index.ts': ` @@ -473,6 +473,9 @@ export default testSuite(async ({ describe }, { tsx, supports, version }: NodeAp const p = await tsx(['index.ts'], { cwd: fixture.path, }); + onTestFail(() => { + console.log(p); + }); expect(p.failed).toBe(false); }); } diff --git a/tests/utils/node-versions.ts b/tests/utils/node-versions.ts index 77e3a7eaa..f8920d28e 100644 --- a/tests/utils/node-versions.ts +++ b/tests/utils/node-versions.ts @@ -13,11 +13,11 @@ export const nodeVersions = [ && process.platform !== 'win32' ) ? [ - latestMajor('22.2.0'), + latestMajor('22.6.0'), '22.0.0', latestMajor('21.7.3'), '21.0.0', - latestMajor('20.14.0'), + latestMajor('20.17.0'), '20.0.0', latestMajor('18.20.3'), '18.0.0',