next-export-optimize-images
next-export-optimize-images copied to clipboard
Cannot complete build
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:
- 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.
- Configure output for export
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "export",
};
module.exports = nextConfig;
- Run
npm run build
and observe succesful build - Install the
next-export-optimize-images
package - Modify
next.config.js
const withExportImages = require("next-export-optimize-images");
/** @type {import('next').NextConfig} */
const nextConfig = withExportImages({
output: "export",
});
module.exports = nextConfig;
- 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
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.
@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
Same on Next 14. (I had to enable experimental webpack builder)
experimental: {
webpackBuildWorker: true,
},
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 :(
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.
Any update on when/if this will be resolved?
No fixes for this still?
https://github.com/dc7290/next-export-optimize-images/issues/796
Ref: https://github.com/dc7290/next-export-optimize-images/issues/820
Fixed release in v4.0.0!