From 97aecbbe7499ab07370f3fcc120095702028cc5a Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sun, 27 Feb 2022 20:17:56 +0800 Subject: [PATCH] fix(mdx-loader): suppress image reading warning in Yarn PnP; log warning instead of error --- .../src/remark/transformImage/__tests__/index.test.ts | 2 +- .../src/remark/transformImage/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/index.test.ts b/packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/index.test.ts index 90cb4fb15bd5..dc1ed9e1710c 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/index.test.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/index.test.ts @@ -59,7 +59,7 @@ describe('transformImage plugin', () => { }); test('does not choke on invalid image', async () => { - const errorMock = jest.spyOn(console, 'error').mockImplementation(); + const errorMock = jest.spyOn(console, 'warn').mockImplementation(); const result = await processFixture('invalid-img', {staticDirs}); expect(result).toMatchSnapshot(); expect(errorMock).toBeCalledTimes(1); diff --git a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts index c5ed71492ec3..75e150564e7a 100644 --- a/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/transformImage/index.ts @@ -67,8 +67,12 @@ async function toImageRequireNode( height = ` height="${size.height}"`; } } catch (err) { - logger.error`The image at path=${imagePath} can't be read correctly. Please ensure it's a valid image. + // Workaround for https://github.com/yarnpkg/berry/pull/3889#issuecomment-1034469784 + // TODO remove this check once fixed in Yarn PnP + if (!process.versions.pnp) { + logger.warn`The image at path=${imagePath} can't be read correctly. Please ensure it's a valid image. ${(err as Error).message}`; + } } Object.keys(jsxNode).forEach(