fix(mdx-loader): suppress image reading warning in Yarn PnP; log warning instead of error (#6779)

This commit is contained in:
Joshua Chen 2022-02-28 10:49:53 +08:00 committed by GitHub
parent 3e5da386ce
commit 9d7ed31661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -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);

View file

@ -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(