@@ -182,6 +182,8 @@ export default defineNuxtModule<ModuleOptions>({
182182 const resolver = createResolver ( import . meta. url )
183183 const { resolve } = resolver
184184 const { version } = await readPackageJSON ( resolve ( '../package.json' ) )
185+ const userAppPkgJson = await readPackageJSON ( nuxt . options . rootDir )
186+ . catch ( ( ) => ( { dependencies : { } , devDependencies : { } } ) )
185187 logger . level = ( config . debug || nuxt . options . debug ) ? 4 : 3
186188 if ( config . enabled === false ) {
187189 logger . debug ( 'The module is disabled, skipping setup.' )
@@ -228,8 +230,12 @@ export default defineNuxtModule<ModuleOptions>({
228230 // avoid any sharp logic if user explicitly opts-out
229231 const userConfiguredExtension = config . defaults . extension
230232 const hasConfiguredJpegs = userConfiguredExtension && [ 'jpeg' , 'jpg' ] . includes ( userConfiguredExtension )
231- const hasSharpDependency = await hasResolvableDependency ( 'sharp' )
232- if ( hasSharpDependency ) {
233+ const allDeps = {
234+ ...( userAppPkgJson . dependencies || { } ) ,
235+ ...( userAppPkgJson . devDependencies || { } ) ,
236+ }
237+ const hasExplicitSharpDependency = 'sharp' in allDeps || ( hasConfiguredJpegs && config . defaults . renderer !== 'chromium' )
238+ if ( hasExplicitSharpDependency ) {
233239 if ( ! targetCompatibility . sharp ) {
234240 logger . warn ( `Rendering JPEGs requires sharp which does not work with ${ preset } . Images will be rendered as PNG at runtime.` )
235241 config . compatibility = defu ( config . compatibility , < CompatibilityFlagEnvOverrides > {
0 commit comments