From 51a305ef94c7e51918f4c957bff861bcc1187723 Mon Sep 17 00:00:00 2001 From: Massimeddu Cireddu Date: Fri, 3 Dec 2021 16:47:38 +0100 Subject: [PATCH] fix: use path.resolve for custom reporters to be compatible with yarn PnP #18922 --- packages/server/lib/reporter.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/server/lib/reporter.js b/packages/server/lib/reporter.js index 5c5b6135c87e..0a0b109732e2 100644 --- a/packages/server/lib/reporter.js +++ b/packages/server/lib/reporter.js @@ -545,8 +545,13 @@ class Reporter { throw err } - p = path.resolve(projectRoot, 'node_modules', reporterName) - + try { + p = path.resolve(projectRoot, 'node_modules', reporterName) + } catch (err) { + // If we are not able to import with path.resolve, try with the require.resolve + // useful for example when Yarn PnP is used. See: #18922 + p = require.resolve(reporterName, { paths: [projectRoot] }) + } // try npm. if this fails, we're out of options, so let it throw debug('trying to require local reporter with path:', p)