diff --git a/src/esm/hook/resolve.ts b/src/esm/hook/resolve.ts index cefb97bd2..39d57bb53 100644 --- a/src/esm/hook/resolve.ts +++ b/src/esm/hook/resolve.ts @@ -124,6 +124,7 @@ export const resolve: resolve = async ( const isPath = ( specifier.startsWith(fileProtocol) || isRelativePathPattern.test(specifier) + || path.isAbsolute(specifier) ); // bare specifier diff --git a/tests/specs/api.ts b/tests/specs/api.ts index 0e330764c..d913c6542 100644 --- a/tests/specs/api.ts +++ b/tests/specs/api.ts @@ -290,6 +290,30 @@ export default testSuite(({ describe }, node: NodeApis) => { expect(stdout).toBe('Fails as expected 1\nfoo bar\nfoo bar\nFails as expected 2'); }); + test('absolute path', async ({ onTestFinish }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.mjs': ` + import path from 'node:path'; + import { fileURLToPath } from 'node:url'; + import { tsImport } from ${JSON.stringify(tsxEsmApiPath)}; + + const __dirname = path.dirname(fileURLToPath(new URL(import.meta.url))); + const moduleAbsolutePath = path.join(__dirname, 'file.ts'); + const { message } = await tsImport(moduleAbsolutePath, import.meta.url); + console.log(message); + `, + ...tsFiles, + }); + onTestFinish(async () => await fixture.rm()); + + const { stdout } = await execaNode(path.join(fixture.path, 'import.mjs'), [], { + nodePath: node.path, + nodeOptions: [], + }); + expect(stdout).toBe('foo bar'); + }); + test('commonjs', async ({ onTestFinish }) => { const fixture = await createFixture({ 'package.json': JSON.stringify({ type: 'module' }),