next-export-optimize-images icon indicating copy to clipboard operation
next-export-optimize-images copied to clipboard

Cannot complete build

Open stavros-k opened this issue 1 year ago • 6 comments

Describe the bug A clear and concise description of what the bug is.

Hello, I was trying to use package to optimize my images. But after following the getting started guide and trying to build, I get the following error.

❯ npm run build                    

> [email protected] build
> next build

info - [next-export-optimize-images]: Configuration was not loaded. (This is optional.)
 ✓ Creating an optimized production build    
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
   Generating static pages (0/5)  [=   ]TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/tmp/test/node_modules/react/cjs/react.production.min.js:24:118)
    at /tmp/test/node_modules/next/dist/client/image-component.js:241:47
    at nh (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:48668)
    at ny (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:52524)
    at nf (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:35987)
    at nh (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:48675)
    at nh (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:49347)
    at ny (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:52524)
    at nv (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:55162)
    at ng (/tmp/test/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:27:54569)

To Reproduce Steps to reproduce the behavior:

  1. Create a new project.
❯ npx create-next-app@latest
Need to install the following packages:
[email protected]
Ok to proceed? (y) y
✔ What is your project named? … test
✔ Would you like to use TypeScript? … No / **Yes**
✔ Would you like to use ESLint? … No / **Yes**
✔ Would you like to use Tailwind CSS? … No / **Yes**
✔ Would you like to use `src/` directory? … **No** / Yes
✔ Would you like to use App Router? (recommended) … No / **Yes**
✔ Would you like to customize the default import alias (@/*)? … **No** / Yes
Creating a new Next.js app in /tmp/test.

Using npm.
  1. Configure output for export
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export",
};

module.exports = nextConfig;
  1. Run npm run build and observe succesful build
  2. Install the next-export-optimize-images package
  3. Modify next.config.js
const withExportImages = require("next-export-optimize-images");

/** @type {import('next').NextConfig} */
const nextConfig = withExportImages({
  output: "export",
});

module.exports = nextConfig;
  1. Try to build, you will see the error

Expected behavior

A successful build.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS] Linux/Ubuntu
  • Browser [e.g. chrome, safari] N/A
  • Version [e.g. 22] N/A

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] N/A
  • OS: [e.g. iOS8.1] N/A
  • Browser [e.g. stock browser, safari] N/A
  • Version [e.g. 22] N/A

Additional context

I'm pretty new to next.js, been trying it for few days only, so it might be user error. I didnt't see any other means to start a discussion, which is why I opened this bug report.

Thanks

stavros-k avatar Oct 21 '23 09:10 stavros-k

Just reproduced it with the actual examples/common.

Rename pages folder to app, and add the required RootLayout:

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
      </body>
    </html>
  );
}

Then the error appear.

tiste avatar Oct 25 '23 11:10 tiste

@stavros-k just succeed by downgrading next from latest 13.5.6 to 13.4.19. Seems to have a bug on it: https://github.com/vercel/next.js/issues/57277

tiste avatar Oct 25 '23 12:10 tiste

Same on Next 14. (I had to enable experimental webpack builder)

    experimental: {
        webpackBuildWorker: true,
    },

stavros-k avatar Oct 26 '23 17:10 stavros-k

Same on Next 14. (I had to enable experimental webpack builder)

    experimental: {
        webpackBuildWorker: true,
    },

@stavros-k I still have issues with next 14 even with this option :(

tiste avatar Oct 27 '23 13:10 tiste

Same on Next 14. (I had to enable experimental webpack builder)

    experimental: {
        webpackBuildWorker: true,
    },

@stavros-k I still have issues with next 14 even with this option :(

Oh, yea should have been clearer. It's still an issue, the webpack option was just an extra thing that next was asking to enable in order to "continue". But it still fails with the same useContext error!

I'll stick with 14 for now, until the fix come from either side, we already had unoptimized images for ever, so it won't hurt for few more days/weeks.

stavros-k avatar Oct 27 '23 13:10 stavros-k

Any update on when/if this will be resolved?

J3tto avatar Nov 24 '23 12:11 J3tto

No fixes for this still?

joebentaylor1995 avatar Jan 29 '24 17:01 joebentaylor1995

https://github.com/dc7290/next-export-optimize-images/issues/796

dc7290 avatar Mar 11 '24 15:03 dc7290

Ref: https://github.com/dc7290/next-export-optimize-images/issues/820

dc7290 avatar Mar 20 '24 14:03 dc7290

Fixed release in v4.0.0!

dc7290 avatar Apr 10 '24 15:04 dc7290