やったこと:
https://www.freecodecamp.org/news/static-site-generation-with-nextjs/
を参考に下記を行いました。
$ npx create-next-app my-static-nextjs-app
$ cd my-static-nextjs-app
この状態で下記を行いブラウザーでローカルホストにアクセスすると正常な画面が表示されました。
$ npm run dev
このあと、サーバーを止めて、
上記記事にある通り package.json の build に next export
を足し下記のようにしました。
"build": "next build && next export"
そして下記を実行。
$ npm run build
そうすると下記エラーが出ました。
Error: Image Optimization using Next.js' default loader is not compatible with `next export`.
Possible solutions:
- Use `next start` to run a server, which includes the Image Optimization API.
- Use any provider which supports Image Optimization (like Vercel).
- Configure a third-party loader in `next.config.js`.
- Use the `loader` prop for `next/image`.
Read more: https://nextjs.org/docs/messages/export-image-api
at /プロジェクトフォルダ名/node_modules/next/dist/export/index.js:257:23
at async Span.traceAsyncFn (/プロジェクトフォルダ名/node_modules/next/dist/telemetry/trace/trace.js:60:20)
ちょっとReactとNext.jsの経験両方ないので、意味がわかっていませんが、
を参考に
index.js
から
import Image from 'next/image'
の行と
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
の行を削除しました。
そして再度、
$ npm run build
すると成功したようで out
フォルダが出来ていました。その中の index.html
は下記です。(ホントは一行で書かれていますが、インデントしてあります)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta charSet="utf-8" />
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
<meta name="next-head-count" content="5" />
<link rel="preload" href="/_next/static/css/120f2e2270820d49a21f.css" as="style" />
<link rel="stylesheet" href="/_next/static/css/120f2e2270820d49a21f.css" data-n-g="" />
<link rel="preload" href="/_next/static/css/eb291d7de33c874d5a88.css" as="style" />
<link rel="stylesheet" href="/_next/static/css/eb291d7de33c874d5a88.css" data-n-p="" /><noscript
data-n-css=""></noscript>
<script defer="" nomodule="" src="/_next/static/chunks/polyfills-a54b4f32bdc1ef890ddd.js"></script>
<script src="/_next/static/chunks/webpack-ddd010a953737b6e3536.js" defer=""></script>
<script src="/_next/static/chunks/framework-b97a0ed4f13ff8397343.js" defer=""></script>
<script src="/_next/static/chunks/main-4809d8b3f3ef3c100198.js" defer=""></script>
<script src="/_next/static/chunks/pages/_app-220ac94ca11b92b10e31.js" defer=""></script>
<script src="/_next/static/chunks/pages/index-9e3d432ffbe84eebc970.js" defer=""></script>
<script src="/_next/static/xeIQbCWm-8qD3c9J2l-Ky/_buildManifest.js" defer=""></script>
<script src="/_next/static/xeIQbCWm-8qD3c9J2l-Ky/_ssgManifest.js" defer=""></script>
</head>
<body>
<div id="__next">
<div class="Home_container__1EcsU">
<main class="Home_main__1x8gC">
<h1 class="Home_title__3DjR7">Welcome to <a href="https://nextjs.org">Next.js!</a></h1>
<p class="Home_description__17Z4F">Get started by editing
<!-- --> <code class="Home_code__axx2Y">pages/index.js</code>
</p>
<div class="Home_grid__2Ei2F"><a href="https://nextjs.org/docs" class="Home_card__2SdtB">
<h2>Documentation →</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a><a href="https://nextjs.org/learn" class="Home_card__2SdtB">
<h2>Learn →</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a><a href="https://github.com/vercel/next.js/tree/master/examples" class="Home_card__2SdtB">
<h2>Examples →</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a><a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
class="Home_card__2SdtB">
<h2>Deploy →</h2>
<p>Instantly deploy your Next.js site to a public URL with Vercel.</p>
</a></div>
</main>
<footer class="Home_footer__1WdhD"><a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank" rel="noopener noreferrer">Powered by
<!-- --> <span class="Home_logo__1YbrH"></span>
</a></footer>
</div>
</div>
<script id="__NEXT_DATA__"
type="application/json">{"props":{"pageProps":{}},"page":"/","query":{},"buildId":"xeIQbCWm-8qD3c9J2l-Ky","nextExport":true,"autoExport":true,"isFallback":false,"scriptLoader":[]}</script>
</body>
</html>
ブラウザでアクセスすると添付画像のようにCSSがあたっていません。

out/_next/static/css/120f2e2270820d49a21f.css
とファイルは存在していますが、index.html
は
/_next/static/css/120f2e2270820d49a21f.css
を参照しにいっているようです。
つまり out
フォルダの記載が index.html
に足りません(早い話が参照しているパスが違います)。
どうすれば、index.html
のhref
は out
フォルダを参照できるようになりますか?(そのようなindex.htmlが生成されますか?)