Unable to automatically determine the location of static site files.
with new Next.js app
#933
-
The instructions at https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/getting-started.md#configure-lighthouse-ci don't seem to work "out-of-the-box" with a Next.js application created today using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
https://github.com/hamirmahal/Lighthouse-CI-with-Next.js-and-TypeScript/actions/runs/5871667159/job/15921591136 reproduces the issue. |
Beta Was this translation helpful? Give feedback.
-
@hamirmahal We have two options:
Custom ServerWe need to tell Lighthouse CI where the "custom server" e.g. the Next.js application is serving the production-like assets. This can be handled by updating module.exports = {
ci: {
collect: {
url: ['http://localhost:3000/'],
startServerCommand: 'npm run start',
},
upload: {
target: 'temporary-public-storage',
},
},
}; See modifications for sites with a custom server. This step is necessary because Next.js is generating HTML files per route, and its not exactly a "static site" without using something like Next's static exports. Static site or providing a build directory to Lighthouse CIIf you enable static exports, when running // next.config.js
const nextConfig = {
output: 'export',
}
module.exports = nextConfig Why does the GitHub Action fail "out of the box"?In your example action run, it fails because Lighthouse CI is expecting a build folder containing production-like assets: dist, _site, out, public, etc or a custom server configured. I believe this is expected behavior since we aren't telling Lighthouse CI where to find the application files. Here is where the error is thrown: https://github.com/GoogleChrome/lighthouse-ci/blob/main/packages/cli/src/autorun/autorun.js#L68-L87 Successful Lighthouse CI GitHub Action with Next.js + TypeScriptI used |
Beta Was this translation helpful? Give feedback.
@hamirmahal We have two options:
lighthouserc.js
to tell Lighthouse CI where the production-like assets from Next.js can be locatedout
which Lighthouse CI will automatically determine and use when running the CI GitHub ActionCustom Server
We need to tell Lighthouse CI where the "custom server" e.g. the Next.js application is serving the production-like assets. This can be handled by updating
lighthouserc.js
: