Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

responsive-loader with sharp error #50

Closed
shenburak opened this issue Dec 19, 2018 · 18 comments
Closed

responsive-loader with sharp error #50

shenburak opened this issue Dec 19, 2018 · 18 comments

Comments

@shenburak
Copy link

I get this error when I use the responsive-loader with sharp, but it works well with the jimp module.

Error: Cannot find module '...node_modules\responsive-loader\lib\index.js/sharp'

-Windows OS

@cyrilwanner
Copy link
Owner

Hi @qeneke
Thank you for reporting this issue! This was my bad, I didn't think about the different directory separator on windows when I wrote the regex for detecting the sharp adapter.
I just published v2.3.1 to npm which should solve this issue.

@vioule
Copy link

vioule commented Aug 18, 2020

Got the same error
Error: Cannot find module '.../node_modules/responsive-loader/lib/cjs.js/sharp'

package.json
  "dependencies": {
    "imagemin-mozjpeg": "^9.0.0",
    "next": "9.5.1",
    "next-optimized-images": "^2.6.2",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "responsive-loader": "^2.0.2",
    "sharp": "^0.25.4",
    "styled-components": "^5.1.1"
  },

I solved the problem like this for the moment in responsive-loader.js

  if (!adapter && detectedLoaders.responsiveAdapter === 'sharp') {
    console.log('wrong :')
    console.log(`${detectedLoaders.responsive}${path.sep}sharp`)
    console.log('right :')
    console.log(`${detectedLoaders.responsive.split('lib')[0]}sharp`)
    // adapter = require(`${detectedLoaders.responsive}${path.sep}sharp`); // <-- old one
    adapter = require(`${detectedLoaders.responsive.split('lib')[0]}sharp`); // <-- new one
  }

wrong :
../node_modules/responsive-loader/lib/cjs.js/sharp
right :
../node_modules/responsive-loader/sharp

@7mioda
Copy link

7mioda commented Aug 19, 2020

I got the same error Error: Cannot find module '.../node_modules/responsive-loader/lib/cjs.js/sharp'

@traversng
Copy link

Im still getting this error with version: 2.6.2. Can we reopen this issue?

@alexis-regnaud
Copy link

alexis-regnaud commented Aug 27, 2020

Same for me. Work with 2.0.0 but not for 2.0.1 and 2.0.2

@hayanisaid
Copy link

I'm having the same issue 😩

@x4th
Copy link

x4th commented Sep 4, 2020

Same issue.

@Germs31
Copy link

Germs31 commented Sep 4, 2020

Same Issue

@mrroll
Copy link

mrroll commented Sep 6, 2020

I've made a PR and a temporary package

mrroll added a commit to mrroll/next-config that referenced this issue Sep 6, 2020
@AdsonCicilioti
Copy link

Same problem.

danielkov added a commit to sportloop/cycloop-portal that referenced this issue Sep 25, 2020
danielkov added a commit to sportloop/cycloop-portal that referenced this issue Sep 25, 2020
* chore(deps): update dependency responsive-loader to v2.1.1

* build: patch dependency next-optimized-images

Temporary fix until following gets addressed:
- Issue: cyrilwanner/next-optimized-images#50
- PR: cyrilwanner/next-optimized-images#201

Co-authored-by: Renovate Bot <[email protected]>
Co-authored-by: Daniel Emod Kovacs <[email protected]>
@AdriaN458
Copy link

For anyone still having this issue, downgrade the package to 2.0.0 for now. Hopefully, it'll be fixed for newer versions.

npm i [email protected]

@jrhager84
Copy link

Any word on a fix for this?

@JohannesSchwegler
Copy link

For anyone still having this issue, downgrade the package to 2.0.0 for now. Hopefully, it'll be fixed for newer versions.

npm i [email protected]

Unfortunately, this is not working for me. Using it with nuxt-optimized-images

@barclayiversen
Copy link

Having this issue, still no fix?

@ojoven
Copy link

ojoven commented Apr 5, 2022

Wow! It's been a long ride!
Same here, same error.

@ojoven
Copy link

ojoven commented Apr 5, 2022

Hey everyone, I didn't try it but I found this on responsive-loader's npm:
https://www.npmjs.com/package/responsive-loader

If you want to use sharp, you need to configure responsive-loader to use its adapter:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.(jpe?g|png|webp)$/i,
        use: [
          loader: 'responsive-loader',
          options: {
            adapter: require('responsive-loader/sharp')
          }
        ]
      }
    ]
  },
}

Not gonna lie, I went for Jimp, but I thought this could help.

@Msulecki
Copy link

Not gonna lie, I went for Jimp, but I thought this could help.

Defining Sharp as adapter in config worked for me, thanks

@FaCRO
Copy link

FaCRO commented May 19, 2022

Adding

  responsive: {
    adapter: require("responsive-loader/sharp"),
  },

to the nextjs config should help, following the implementation at

let adapter = responsive ? responsive.adapter : undefined;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests