1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Netlifyにnext.jsをデプロイする際、「TypeError: Cannot read properties of undefined (reading 'query')」というエラーが発生した

Last updated at Posted at 2025-05-15

概要

NetlifyにNext.jsのプロジェクトをデプロイしようとした際、下記のエラーが発生して失敗した。

TypeError: Cannot read properties of undefined (reading 'query')

原因

@next/bundle-analyzerが常に実行する様に設定されていたのが原因だった。

そのため、analyzerを削除したらデプロイできた。

エラーメッセージ全文

7:22:18 AM: Netlify Build                                                 
7:22:18 AM: ────────────────────────────────────────────────────────────────
7:22:18 AM: ​
7:22:18 AM: ❯ Version
7:22:18 AM:   @netlify/build 33.0.0
7:22:18 AM: ​
7:22:18 AM: ❯ Flags
7:22:18 AM:   accountId: 682514ae2513bd4eda33be58
7:22:18 AM:   baseRelDir: true
7:22:18 AM:   buildId: 68251788ef25dd4d1d0c0c8f
7:22:18 AM:   deployId: 68251788ef25dd4d1d0c0c91
7:22:18 AM: ​
7:22:18 AM: ❯ Current directory
7:22:18 AM:   /opt/build/repo
7:22:18 AM: ​
7:22:18 AM: ❯ Config file
7:22:18 AM:   No config file was defined: using default values.
7:22:18 AM: ​
7:22:18 AM: ❯ Context
7:22:18 AM:   production
7:22:19 AM: ​
7:22:19 AM: ❯ Using Next.js Runtime - v5.11.1
7:22:21 AM: No Next.js cache to restore
7:22:21 AM: ​
7:22:21 AM: Build command from Netlify app                                
7:22:21 AM: ────────────────────────────────────────────────────────────────
7:22:21 AM: ​
7:22:21 AM: $ bun run build
7:22:21 AM: $ ANALYZE=false next build
7:22:21 AM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
7:22:21 AM:    ▲ Next.js 15.3.2
7:22:21 AM:    Creating an optimized production build ...
7:22:31 AM: <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (120kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
7:22:35 AM:  ✓ Compiled successfully in 13.0s
7:22:35 AM:    Linting and checking validity of types ...
7:22:40 AM:    Collecting page data ...
7:22:43 AM: TypeError: Cannot read properties of undefined (reading 'query')
7:22:43 AM:     at new g (.next/server/chunks/473.js:1:12709)
7:22:43 AM:     at y.createSession (.next/server/chunks/473.js:1:13754)
7:22:43 AM:     at v (.next/server/chunks/473.js:1:14926)
7:22:43 AM:     at S (.next/server/chunks/473.js:1:15237)
7:22:43 AM:     at 25713 (.next/server/chunks/999.js:1:168)
7:22:43 AM:     at t (.next/server/webpack-runtime.js:1:128)
7:22:43 AM:     at 75362 (.next/server/chunks/999.js:1:5485)
7:22:43 AM:     at t (.next/server/webpack-runtime.js:1:128)
7:22:43 AM:     at 88556 (.next/server/app/api/subscriptions/route.js:1:739)
7:22:43 AM:     at t (.next/server/webpack-runtime.js:1:128)
7:22:43 AM: > Build error occurred
7:22:43 AM: [Error: Failed to collect page data for /api/subscriptions] {
7:22:43 AM:   type: 'Error'
7:22:43 AM: }
7:22:43 AM: error: script "build" exited with code 1
7:22:43 AM: ​
7:22:43 AM: "build.command" failed                                        
7:22:43 AM: ────────────────────────────────────────────────────────────────
7:22:43 AM: ​
7:22:43 AM:   Error message
7:22:43 AM:   Command failed with exit code 1: bun run build (https://ntl.fyi/exit-code-1)
7:22:43 AM: ​
7:22:43 AM:   Error location
7:22:43 AM:   In Build command from Netlify app:
7:22:43 AM:   bun run build
7:22:43 AM: ​
7:22:43 AM:   Resolved config
7:22:43 AM:   build:
7:22:43 AM:     command: bun run build
7:22:43 AM:     commandOrigin: ui
7:22:43 AM:     publish: /opt/build/repo/.next
7:22:43 AM:     publishOrigin: ui
7:22:43 AM:   plugins:
7:22:43 AM:     - inputs: {}
7:22:43 AM:       origin: ui
7:22:43 AM:       package: '@netlify/plugin-nextjs'
7:22:43 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:22:44 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
7:22:44 AM: Failing build: Failed to build site
7:22:44 AM: Finished processing build request in 41.783s
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?