質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.41%
Netlify

Netlifyは、静的サイトを超高速でホスティングできる高機能なWebサービスです。WordPressといった動的処理を必要としないLPなどの静的Webサイトを公開することが可能。カスタムドメイン設定や無料SSL証明書などの多くの機能を無料で使用できます。

Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

Q&A

0回答

1096閲覧

【Netlify】ビルド時にエラーが発生する

teto_plw

総合スコア57

Netlify

Netlifyは、静的サイトを超高速でホスティングできる高機能なWebサービスです。WordPressといった動的処理を必要としないLPなどの静的Webサイトを公開することが可能。カスタムドメイン設定や無料SSL証明書などの多くの機能を無料で使用できます。

Next.js

Next.jsは、Reactを用いたサーバサイドレンダリングなどを行う軽量なフレームワークです。Zeit社が開発しており、nextコマンドでプロジェクトを作成することにより、開発環境整備が整った環境が即時に作成できます。

0グッド

0クリップ

投稿2022/09/29 11:05

編集2022/09/29 11:06

前提

NetlifyにNext.jsで作成したプロジェクトをデプロイしています。

実現したいこと

next-sitemapでサイトマップを作成したく、例えば下記のURLのようにやってみているのですが、
Netlifyで『next build』以外を指定すると ビルドエラーとなってしまいます。
『next build』だとエラーは出ませんが、サイトマップは作成されません。
https://fwywd.com/tech/next-sitemap

どのようにしたらサイトマップが作成され、デプロイも行われるでしょうか?

発生している問題・エラーメッセージ

──────────────────────────────────────────────────────────────── Netlify Build ──────────────────────────────────────────────────────────────── ​ ❯ Version @netlify/build 27.18.6 ​ ❯ Flags baseRelDir: true buildId: 63355d05d8ccec0008a84bf9 deployId: 63355d05d8ccec0008a84bfb ​ ❯ Current directory /opt/build/repo/my-blog ​ ❯ Config file /opt/build/repo/my-blog/netlify.toml ​ ❯ Context production ​ ❯ Using Next.js Runtime - v4.23.2 ​ ──────────────────────────────────────────────────────────────── 1. @netlify/plugin-nextjs (onPreBuild event) ──────────────────────────────────────────────────────────────── ​ Next.js cache restored. Not running Next Runtime ​ (@netlify/plugin-nextjs onPreBuild completed in 123ms) ​ ──────────────────────────────────────────────────────────────── 2. Build command from Netlify app ──────────────────────────────────────────────────────────────── ​ $ npm run build npm WARN config tmp This setting is no longer used. npm stores temporary files in a special npm WARN config location in the cache, and they are managed by npm WARN config [`cacache`](http://npm.im/cacache). > newt-blog2-starter-nextjs@1.0.0 build > next build && next export warn - The `target` config is deprecated and will be removed in a future version. See more info here https://nextjs.org/docs/messages/deprecated-target-config Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating info - Checking validity of types... Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating info - Creating an optimized production build... Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating info - Compiled successfully info - Collecting page data... info - Generating static pages (0/30) info - Generating static pages (7/30) info - Generating static pages (14/30) info - Generating static pages (22/30) info - Generating static pages (30/30) info - Finalizing page optimization... Page Size First Load JS ┌ ● / (1779 ms) 507 B 123 kB ├ /_app 0 B 72.1 kB ├ λ /404 2.45 kB 74.5 kB ├ ● /archive/[slug] (1864 ms) 518 B 123 kB ├ └ /archive/2022 (1864 ms) ├ ● /archive/[slug]/page/[page] (1826 ms) 527 B 123 kB ├ └ /archive/2022/page/1 (1826 ms) ├ ● /article/[slug] (4401 ms) 4.22 kB 187 kB ├ ├ /article/newt-blog2 (1503 ms) ├ ├ /article/ ManagementPolicy1 (1474 ms) ├ └ /article/newt-blog1 (1424 ms) ├ ● /author/[slug] (1816 ms) 518 B 123 kB ├ └ /author/teto (1816 ms) ├ ● /author/[slug]/page/[page] (1797 ms) 527 B 123 kB ├ └ /author/teto/page/1 (1797 ms) ├ ○ /Inquiry (999 ms) 1.98 kB 90.9 kB ├ └ css/a22acf05b8be9443.css 1.1 kB ├ ○ /Licence (1208 ms) 2.97 kB 91.9 kB ├ ● /page/[page] (1830 ms) 517 B 123 kB ├ └ /page/1 (1830 ms) ├ ○ /PrivacyPolicy (1218 ms) 4.84 kB 93.7 kB ├ ● /search (1396 ms) 21.8 kB 184 kB ├ └ css/56d23cf654860bf0.css 1.43 kB ├ ● /tag/[slug] (7057 ms) 516 B 123 kB ├ ├ /tag/development (1839 ms) ├ ├ /tag/react-nextjs (1748 ms) ├ ├ /tag/blog (1739 ms) ├ └ /tag/notes (1731 ms) └ ● /tag/[slug]/page/[page] (24610 ms) 524 B 123 kB ├ /tag/react-nextjs/page/2 (2078 ms) ├ /tag/react-nextjs/page/3 (2070 ms) ├ /tag/react-nextjs/page/5 (2069 ms) ├ /tag/react-nextjs/page/4 (2045 ms) ├ /tag/react-nextjs/page/8 (1951 ms) ├ /tag/react-nextjs/page/6 (1940 ms) ├ /tag/development/page/1 (1875 ms) └ [+6 more paths] (avg 1764 ms) + First Load JS shared by all 72.1 kB ├ chunks/framework-5f4595e5518b5600.js 42 kB ├ chunks/main-01df828e572375b9.js 27.6 kB ├ chunks/pages/_app-3e2d95c03c8c2a5f.js 1.53 kB ├ chunks/webpack-cb7634a8b6194820.js 884 B └ css/53017e237851091b.css 289 B λ (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps) ○ (Static) automatically rendered as static HTML (uses no initial props) ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps) warn - The `target` config is deprecated and will be removed in a future version. See more info here https://nextjs.org/docs/messages/deprecated-target-config Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating info - using build directory: /opt/build/repo/my-blog/.next info - Copying "static build" directory info - No "exportPathMap" found in "/opt/build/repo/my-blog/next.config.js". Generating map from "./pages" 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 /opt/build/repo/my-blog/node_modules/next/dist/export/index.js:257:23 at async Span.traceAsyncFn (/opt/build/repo/my-blog/node_modules/next/dist/trace/trace.js:75:20) ​ ──────────────────────────────────────────────────────────────── "build.command" failed ──────────────────────────────────────────────────────────────── ​ Error message Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1) ​ Error location In Build command from Netlify app: npm run build ​ Resolved config build: base: /opt/build/repo/my-blog command: npm run build commandOrigin: ui environment: - NEXT_PUBLIC_GOOGLE_FORM_URL - NEXT_PUBLIC_NEWT_API_TOKEN - NEXT_PUBLIC_NEWT_API_TYPE - NEXT_PUBLIC_NEWT_APP_UID - NEXT_PUBLIC_NEWT_ARTICLE_MODEL_UID - NEXT_PUBLIC_NEWT_AUTHOR_MODEL_UID - NEXT_PUBLIC_NEWT_SPACE_UID - NEXT_PUBLIC_NEWT_TAG_MODEL_UID - NEXT_PUBLIC_PAGE_LIMIT - SITE_URL - NETLIFY_NEXT_PLUGIN_SKIP publish: /opt/build/repo/my-blog/.next publishOrigin: ui plugins: - inputs: {} origin: config package: '@netlify/plugin-nextjs' Caching artifacts Started saving node modules Finished saving node modules Started saving build plugins Finished saving build plugins Started saving yarn cache Finished saving yarn cache Started saving pip cache Finished saving pip cache Started saving emacs cask dependencies Finished saving emacs cask dependencies Started saving maven dependencies Finished saving maven dependencies Started saving boot dependencies Finished saving boot dependencies Started saving rust rustup cache Finished saving rust rustup cache Started saving go dependencies Finished saving go dependencies Build failed due to a user error: Build script returned non-zero exit code: 2 Creating deploy upload records Failing build: Failed to build site Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2) Finished processing build request in 46.588910191s

該当のソースコード

netlify.toml

[build] command = "next build" //ここ変更するとビルドエラーになってしまう。 [[plugins]] package = "@netlify/plugin-nextjs"

package.json

"scripts": { "dev": "next dev", "build": "next build", "postbuild": "next-on-netlify", "export": "next export", "postexport": "next-sitemap", "deploy": "npm run build && npm run export", "start": "next start", "lint": "next lint" }

next-sitemap.js

module.exports = { siteUrl: "https://teto-tech.com/", changefreq: "weekly", generateRobotsTxt: true, sitemapSize: 7000, outDir: "./out", };

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.41%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問