fix(support): Require the optional sharp dep properly from mjpeg module (#18769)

This commit is contained in:
Mykola Mokhnach
2023-06-14 18:17:25 +00:00
committed by GitHub
parent d0ebbaa0c6
commit c18eb03261
2 changed files with 3 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ let _sharp;
/**
* @returns {import('sharp')}
*/
function requireSharp() {
export function requireSharp() {
if (!_sharp) {
try {
_sharp = require('sharp');

View File

@@ -1,7 +1,7 @@
import _ from 'lodash';
import log from './logger';
import B from 'bluebird';
import sharp from 'sharp';
import {requireSharp} from './image-util';
import {Writable} from 'stream';
import {requirePackage} from './node';
import axios from 'axios';
@@ -77,7 +77,7 @@ class MJpegStream extends Writable {
}
try {
return await sharp(lastChunk).png().toBuffer();
return await requireSharp()(lastChunk).png().toBuffer();
} catch (e) {
return null;
}