question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next12.2 future/image support

See original GitHub issue

Describe the bug

Using the experimental “allowFutureImage” with storybook, it throw Error.

The "next/future/image" component is experimental and may be subject to breaking changes. To enable this experiment, please include `experimental: { images: { allowFutureImage: true } }` in your next.config.js file.

Your minimal, reproducible example

nextjs example with-storybook-app

Steps to reproduce

  1. npx create-next-app --example with-storybook with-storybook-app
  2. add experimental config
// next.config.js
module.exports = {
  ...
  experimental: {
    images: {
      allowFutureImage: true,
    },
  },
}
  1. replace “next/image” to “next/future/image”
// pages/nextjsImages.js
import Image from 'next/future/image'

Expected behavior

with next.config.js setup, the stories including future/image should load without error.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • mac OS
  • Chrome (102.0.5005.115)

storybook-addon-next version

1.6.7

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:20
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dawidk92commented, Aug 23, 2022

Workaround with support of fill property from v12.2.4

// .storybook/preview.js

import * as NextFutureImage from "next/future/image";

Object.defineProperty(NextFutureImage, "default", {
  configurable: true,
  value: (props) => {
    const { fill, ...restProps } = props;

    return (
      <img
        {...restProps}
        style={
          fill
            ? {
                position: "absolute",
                height: "100%",
                width: "100%",
                inset: 0,
                color: "transparent",
              }
            : undefined
        }
      />
    );
  },
});
3reactions
Karibashcommented, Sep 14, 2022

I think this is the simplest solution.

import Image from 'next/future/image';

const OriginalImage = Image.default;
Object.defineProperty(Image, 'default', {
  configurable: true,
  value: props => <OriginalImage {...props} unoptimized />,
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Next.js 12.2
Improvements to next/image : Including a new next/future/image ... Next.js now also supports using the Edge Runtime for API Routes.
Read more >
How to Use the New <next/image> Component
Next.js 12.2 includes a totally revised component for image optimization. Let's see what has changed.
Read more >
Next.js automatic image optimization with next/image
Learn about automatic image optimization and how it can benefit developers with the native, game-changing, and powerful next/image API.
Read more >
Enable styling of next/image outer wrapper #22861 - GitHub
g-elwell asked this question in Help ... There also seems to be a lack of support for <style jsx> className styles ... https://nextjs.org/blog/next-12-2...
Read more >
How to enable NextJS "next/future/image"? - Stack Overflow
For Next v13 users: I believe next/future/image is now the default Image component. So no additional work necessary! Just import and use
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found