diff --git a/src/loader.ts b/src/loader.ts index 4dff9c6..fe63d0b 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -81,14 +81,21 @@ async function ESBuildLoader( } else { /* Detect tsconfig file */ - // Don't look for tsconfig.json based on external sources (see - // https://github.com/privatenumber/esbuild-loader/issues/363) - if (resourcePath.match(/node_modules/) !== null) { - return; + let tsconfig; + + try { + // Webpack shouldn't be loading the same path multiple times so doesn't need to be cached + tsconfig = getTsconfig(resourcePath, 'tsconfig.json', tsconfigCache); + } catch (error) { + if (resourcePath.split(path.sep).includes('node_modules')) { + this.emitWarning( + new Error(`[esbuild-loader] Error while discovering tsconfig.json in dependency: "${error?.toString()}"`), + ); + } else { + throw error; + } } - // Webpack shouldn't be loading the same path multiple times so doesn't need to be cached - const tsconfig = getTsconfig(resourcePath, 'tsconfig.json', tsconfigCache); if (tsconfig) { const fileMatcher = createFilesMatcher(tsconfig); transformOptions.tsconfigRaw = fileMatcher(resourcePath) as TransformOptions['tsconfigRaw']; diff --git a/tests/specs/tsconfig.ts b/tests/specs/tsconfig.ts index 000b426..5e59659 100644 --- a/tests/specs/tsconfig.ts +++ b/tests/specs/tsconfig.ts @@ -269,12 +269,9 @@ export default testSuite(({ describe }) => { // Fake external dependency node_modules: { 'fake-lib': { - 'index.js': 'export function testFn() { return "Hi!" }', + 'index.ts': 'export function testFn(): string { return "Hi!" }', 'package.json': JSON.stringify({ name: 'fake-lib', - exports: { - '.': './index.js', - }, }), 'tsconfig.json': tsconfigJson({ extends: 'something-imaginary', @@ -302,6 +299,10 @@ export default testSuite(({ describe }) => { }, }, + resolve: { + extensions: ['.ts', '.js'], + }, + module: { rules: [ { @@ -330,9 +331,10 @@ export default testSuite(({ describe }) => { } catch (error) { result = error as ExecaError; } - const { exitCode, stderr } = result; + const { exitCode, stdout } = result; - expect(stderr).not.toMatch("File 'something-imaginary' not found."); + // We log this as a warning, and continue the transform + expect(stdout).toMatch("Error while discovering tsconfig.json in dependency: \"Error: File 'something-imaginary' not found.\""); expect(exitCode).toEqual(0); }); });