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

images not showing, src= object #204

Closed
BernardA opened this issue Sep 9, 2020 · 8 comments
Closed

images not showing, src= object #204

BernardA opened this issue Sep 9, 2020 · 8 comments

Comments

@BernardA
Copy link

BernardA commented Sep 9, 2020

"next-optimized-images": "^2.6.2"

Images are not showing. The resulting HTML is like below:

    <img src="[object Module]" alt="quiamo logo" class="jss7">

Image originals are stored on /public/images as per Nextjs docs.

I run both npm run dev and npm run build with the same result.

For build I also checked on /.next/static/ and found no folder named images as I understand it should be the case.

next.config.js

    const { createSecureHeaders } = require('next-secure-headers');
    const withOptimizedImages = require('next-optimized-images');

 module.exports = withOptimizedImages({
     async headers() {
        return [{ source: '/(.*)', headers: createSecureHeaders() }];
    },
 });

On /src/components/header.js

 ....
               <Link href="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/" aria-label="go to homepage">
                    <img
                        src={require('../../public/images/main-logo.png')}
                        alt="quiamo logo"
                        className={classes.branding}
                    />
                </Link>

Excerpt from package.json

    "imagemin-mozjpeg": "^9.0.0",
    "imagemin-optipng": "^8.0.0",
    "imagemin-svgo": "^8.0.0",
    "localforage": "^1.9.0",
    "mui-datatables": "^3.3.1",
    "next": "^9.5.3",
    "next-compose-plugins": "^2.2.0",
    "next-images": "^1.4.1",
    "next-optimized-images": "^2.6.2",
    "next-redux-saga": "^4.1.2",
    "next-redux-wrapper": "^6.0.2",
    "pdf-viewer-reactjs": "^2.0.7",
    "prop-types": "^15.7.2",
    "react": "16.13.1",
    "react-cookie": "^4.0.3",
    "react-device-detect": "^1.13.1",
    "react-dnd": "^11.1.3",
    "react-dom": "16.13.1",
    "react-geocode": "^0.2.1",
    "react-html-parser": "^2.0.2",
    "react-image-crop": "^8.6.4",
    "react-images": "^1.1.7",
    "react-lazyload": "^3.0.0",
    "react-paginate": "^6.3.2",
    "react-quill": "^1.3.5",
    "react-redux": "^7.2.1",
    "react-social-login": "^3.4.8",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-form": "^8.3.6",
    "redux-saga": "^1.1.3",
    "sass": "^1.26.10",
    "webp-loader": "^0.6.0"
@kovart
Copy link

kovart commented Sep 14, 2020

I have the same issue. It seems the bug occurs only in builds of static pages.
When I run dev server everything works fine.

@taisreis67
Copy link

I have exactly the same issue :(

@andreisergiu98
Copy link

Try require('image.png').default

@antheus-s
Copy link

Try require('image.png').default

This fixed all my issues, thanks!

@BernardA
Copy link
Author

That did work. Thanks @andreisergiu98

To be clear, one needs the full path and, if you use ESLint, you have to disable global require:

     // eslint-disable-next-line global-require
     src={require('../../public/images/main-logo.png').default}

@bymoe
Copy link

bymoe commented Nov 24, 2020

Can we re-open this please? This error still happening, Adding .default does fix it for some images and broke it for some, Not sure what's happening.

@halas
Copy link

halas commented Jan 14, 2021

I have the same problem and although default solves it, I feel it is still a problem that needs addressing as it is not in documentation :)

@louisgv
Copy link

louisgv commented Jan 25, 2021

This seems to only happens with files that were under the inlineimagelimit threshold which get turned into a data string.

The temporary fix seems to be setting inlineimagelimit to -1 and update to 3.0 once it's stable

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

8 participants