質問するログイン新規登録
Next.js

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

Vercel

Vercelとは、フロントエンド開発向けのフレームワークです。静的サイトとサーバレス機能のためのクラウドプラットフォームで、簡単にWebサイトやWebサービスをデプロイできます。自動でスケールでき、監視や各種設定も必要ありません。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

184閲覧

Vercelでのデプロイ時に「RangeError: Maximum call stack size exceeded」が発生 - ローカルビルドは成功するが、Vercel環境でのビルドが失敗

powerchan

総合スコア1

Next.js

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

Vercel

Vercelとは、フロントエンド開発向けのフレームワークです。静的サイトとサーバレス機能のためのクラウドプラットフォームで、簡単にWebサイトやWebサービスをデプロイできます。自動でスケールでき、監視や各種設定も必要ありません。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2025/08/28 12:16

編集2025/08/28 12:20

0

0

実現したいこと

Vercel環境でのビルド成功

  • 本番環境への正常なデプロイ

発生している問題・分からないこと

質問の文脈

問題の概要

  • Vercelでのデプロイ時に「RangeError: Maximum call stack size exceeded」が発生
  • ローカルビルドは成功するが、Vercel環境でのビルドが失敗
  • ビルドトレース収集時のmicromatchパターンマッチングで無限ループ

発生環境

  • ローカル: 成功
  • Vercel: 失敗
  • エラー箇所: ビルドトレース収集時

試行した解決策

  • 設定ファイルの最適化
  • Webpack設定の調整
  • 依存関係の再インストール
  • 環境変数での無効化

期待する結果

  • Vercel環境でのビルド成功
  • 本番環境への正常なデプロイ

エラーメッセージ

error

1RangeError: Maximum call stack size exceeded 2at parse (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:6313) 3at picomatch.makeRe (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:21670) 4at picomatch (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19637) 5at /vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19294 6at Array.map (<anonymous>) 7at picomatch (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:19286) 8at micromatch.isMatch (/vercel/path0/node_modules/next/dist/compiled/micromatch/index.js:15:1090) 9at /vercel/path0/node_modules/next/dist/build/collect-build-traces.js:245:48 10at shouldIgnore (/vercel/path0/node_modules/next/dist/build/collect-build-traces.js:75:9) 11at shouldIgnore (/vercel/path0/node_modules/next/dist/build/collect-build-traces.js:86:23

該当のソースコード

package.json

1{ 2 "name": "sozai", 3 "version": "0.1.0", 4 "private": true, 5 "engines": { 6 "node": "20.x" 7 }, 8 "scripts": { 9 "dev": "next dev", 10 "dev:nodemon": "nodemon --exec \"next dev\"", 11 "build": "NEXT_DISABLE_BUILD_TRACES=true NEXT_DISABLE_COLLECT_BUILD_TRACES=true next build", 12 "start": "next start", 13 "start:nodemon": "nodemon --exec \"next start\"", 14 "lint": "next lint", 15 "resize-images": "node scripts/resize-images.js", 16 "resize-images:smart": "node scripts/resize-images-smart.js", 17 "resize-images:force": "node scripts/resize-images-smart.js --force", 18 "resize-images:help": "node scripts/resize-images.js --help", 19 "create-samples": "node scripts/create-sample-images.js", 20 "process-all": "npm run create-samples && npm run resize-images:smart" 21 }, 22 "dependencies": { 23 "lucide-react": "^0.303.0", 24 "next": "14.0.4", 25 "react": "^18", 26 "react-dom": "^18", 27 "sharp": "^0.34.3", 28 "swiper": "^11.2.10" 29 }, 30 "devDependencies": { 31 "@types/node": "^20", 32 "@types/react": "^18", 33 "@types/react-dom": "^18", 34 "autoprefixer": "^10.0.1", 35 "eslint": "^8", 36 "eslint-config-next": "14.0.4", 37 "nodemon": "^3.1.10", 38 "postcss": "^8", 39 "tailwindcss": "^3.3.0", 40 "typescript": "^5" 41 } 42}

javascript

1/** @type {import('next').NextConfig} */ 2const nextConfig = { 3 images: { 4 domains: ['localhost', 'your-bucket.r2.cloudflarestorage.com'], 5 unoptimized: false, 6 }, 7 // 実験的機能を無効化 8 experimental: { 9 serverComponentsExternalPackages: [], 10 instrumentationHook: false, 11 }, 12 // Webpack設定でビルドトレース関連の問題を防ぐ 13 webpack: (config, { isServer, dev }) => { 14 if (!isServer) { 15 config.resolve.fallback = { 16 ...config.resolve.fallback, 17 fs: false, 18 path: false, 19 os: false, 20 crypto: false, 21 stream: false, 22 util: false, 23 }; 24 } 25 26 // ビルドトレース関連のプラグインを無効化 27 config.plugins = config.plugins.filter(plugin => { 28 return !(plugin.constructor.name === 'BuildTracePlugin' || 29 plugin.constructor.name === 'TracePlugin'); 30 }); 31 32 // ビルドトレース関連のルールを無効化 33 config.module.rules = config.module.rules.filter(rule => { 34 if (rule.use && Array.isArray(rule.use)) { 35 return !rule.use.some(use => 36 use.loader && use.loader.includes('build-traces') 37 ); 38 } 39 return true; 40 }); 41 42 // ビルドトレース関連の最適化を無効化 43 config.optimization = { 44 ...config.optimization, 45 splitChunks: { 46 ...config.optimization.splitChunks, 47 cacheGroups: { 48 ...config.optimization.splitChunks.cacheGroups, 49 default: false, 50 vendors: false, 51 }, 52 }, 53 }; 54 55 // ビルドトレース関連の設定を無効化 56 config.infrastructureLogging = { 57 level: 'error', 58 }; 59 60 return config; 61 }, 62 // 基本的な設定 63 swcMinify: true, 64 compress: true, 65 // ビルド時の最適化 66 poweredByHeader: false, 67 generateEtags: false, 68 // ビルドトレースを無効化 69 onDemandEntries: { 70 maxInactiveAge: 25 * 1000, 71 pagesBufferLength: 2, 72 }, 73 // 静的ファイルの最適化 74 staticPageGenerationTimeout: 120, 75 // ビルドトレースを無効化 76 distDir: '.next', 77 optimizeFonts: false, 78 // ビルドトレースを無効化 79 generateBuildId: async () => { 80 return 'build-' + Date.now(); 81 }, 82 // 出力設定 83 output: 'standalone', 84 // ビルド時の最適化 85 typescript: { 86 ignoreBuildErrors: false, 87 }, 88 eslint: { 89 ignoreDuringBuilds: false, 90 }, 91} 92 93module.exports = nextConfig

vercel.json

1{ 2 "framework": "nextjs", 3 "buildCommand": "npm run build", 4 "installCommand": "npm install", 5 "outputDirectory": ".next" 6}
# 最小限の除外設定(micromatchの問題を回避) node_modules .next .git *.log .env* # 画像ディレクトリ(ビルドトレースの問題を防ぐ) public/images public/images/originals public/images/thumbnails public/images/illustrations # 画像ファイル(具体的な拡張子) *.png *.jpg *.jpeg *.gif *.svg *.webp # 開発用ファイル scripts *.md *.html env.example # キャッシュファイル .resize-cache.json *.cache *.tmp *.temp # ビルド関連ファイル .vercelignore vercel.json
sozai/ ├── app/ │ ├── components/ │ │ ├── IllustrationCard.tsx │ │ ├── ImageSlideshow.tsx │ │ ├── Modal.tsx │ │ ├── RankingItem.tsx │ │ └── Hero.tsx │ ├── data/ │ │ └── illustrations.ts │ ├── types/ │ │ └── illustration.ts │ ├── api/ │ │ └── downloads/ │ │ └── route.ts │ ├── terms/ │ │ └── page.tsx │ ├── globals.css │ ├── layout.tsx │ └── page.tsx ├── public/ │ └── images/ │ ├── originals/ │ ├── thumbnails/ │ └── illustrations/ ├── scripts/ │ ├── resize-images.js │ └── resize-images-smart.js ├── package.json ├── next.config.js ├── vercel.json ├── .vercelignore └── tailwind.config.js

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

試行した解決策

1. 依存関係の再インストール

  • rm -rf node_modules package-lock.json
  • npm install

2. Node.jsバージョンの統一

  • package.json: "node": "20.x"

3. ビルドトレース関連プラグインの無効化

  • Webpack設定でBuildTracePluginとTracePluginを除外

4. ビルドトレース関連ルールの無効化

  • build-tracesを含むローダーを除外

5. ビルド最適化の無効化

  • splitChunksのcacheGroupsを無効化

6. 環境変数でのビルドトレース無効化

  • NEXT_DISABLE_BUILD_TRACES=true
  • NEXT_DISABLE_COLLECT_BUILD_TRACES=true

7. .vercelignoreの最適化

  • 画像ファイルとディレクトリの除外

8. vercel.jsonの最適化

  • 明示的なビルド設定

同様のエラーが同じように表示され、vercel環境でデプロイできなかった

Node.jsバージョン

Node.js: v20.12.0

Next.jsバージョン

Next.js: 14.0.4

オペレーティングシステム

OS: macOS 24.1.0 (darwin)

パッケージマネージャー

npm: 10.x.x

補足

特になし

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

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

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

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

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

FKM

2025/09/04 00:42 編集

そのエラーですが無限ループに限らず、容量オーバーの場合も出ることがあります。ローカルで成功して、デプロイで失敗しているということは、デプロイ先のメモリ容量に耐えられなくなっている可能性が疑われます。 ローカル環境でのメモリ負荷を調べてみては?
powerchan

2025/09/04 11:33

コメントありがとうございます。容量を確認し、改善したところ問題が解決しました! ベストアンサーに選びたいので同じ内容を回答欄に投稿いただけますでしょうか?
guest

回答1

0

ベストアンサー

RangeError: Maximum call stack size exceededというエラーは、無限ループによって発生することが多いですが、厳密に言えば無限ループで、メモリーオーバーが起きたことに対して発生するエラーです。

したがって、必ずしも無限ループで起きるとは限らず、大容量のファイルなどをスクレイピングした場合などで、メモリーオーバーを起こしても発生する可能性はあります。

今回は開発環境でエラーを起こさず本番環境でエラーを起こしているので、本番環境においてメモリオーバーを起こしている可能性が疑われます。その場合は、まず開発環境でどのぐらいメモリを消費しているのか、そしてそれに本番環境が耐えられているのかを確認していくといいでしょう。

投稿2025/09/05 06:41

編集2025/09/05 06:44
FKM

総合スコア3675

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

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

powerchan

2025/09/06 07:10

回答ありがとうございます。 試したところ問題が解決しました! ベストアンサーに選ばせていただきました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.30%

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

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

質問する

関連した質問