Can't recieve data from graphql server when depolying my nextjs app on netlify

Hi,

I’m trying to deploying my Nextjs app, but I’m unable to have the application build successfully on Netlify. To make the context clear. I have an app already deployed my app on vercel and on a PR I’m trying to see whether I can deploy from my PR before changing the main build,I depolyed my graphql server on render and have the cors and environment variables setted both backend and client app,but I still get a 404 error.someone help me please.

You can find the deployed app here.

From the build I can see the following debug log:

5:35:12 PM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/bottomthink/builds
5:38:27 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:36:57 PM: build-image version: 310cc3c813338a2ca47a215a1ab6889dc6ff6cb7 (focal)
5:36:57 PM: buildbot version: d59e91ad7b9655bc2253d9308f8d23584a0c6ed8
5:36:57 PM: Fetching cached dependencies
5:36:57 PM: Failed to fetch cache, continuing with build
5:36:57 PM: Starting to prepare the repo for build
5:36:58 PM: No cached dependencies found. Cloning fresh repo
5:36:58 PM: git clone --filter=blob:none https://github.com/BrainEno/bot-thk-web
5:36:58 PM: Preparing Git Reference refs/heads/feature
5:37:00 PM: Starting to install dependencies
5:37:01 PM: Python version set to 3.8
5:37:01 PM: Attempting Ruby version 2.7.2, read from environment
5:37:01 PM: Using Ruby version 2.7.2
5:37:02 PM: Started restoring cached go cache
5:37:02 PM: Finished restoring cached go cache
5:37:02 PM: go version go1.19.11 linux/amd64
5:37:02 PM: Using PHP version 8.0
5:37:03 PM: v18.16.1 is already installed.
5:37:03 PM: Now using node v18.16.1 (npm v9.5.1)
5:37:03 PM: Enabling Node.js Corepack
5:37:03 PM: Started restoring cached build plugins
5:37:03 PM: Finished restoring cached build plugins
5:37:03 PM: Started restoring cached corepack dependencies
5:37:03 PM: Finished restoring cached corepack dependencies
5:37:03 PM: Started restoring cached yarn cache
5:37:03 PM: Finished restoring cached yarn cache
5:37:04 PM: No yarn workspaces detected
5:37:04 PM: Started restoring cached node modules
5:37:04 PM: Finished restoring cached node modules
5:37:04 PM: Installing npm packages using Yarn version 1.22.19
5:37:04 PM: yarn install v1.22.19
5:37:04 PM: [1/4] Resolving packages...
5:37:04 PM: [2/4] Fetching packages...
5:37:42 PM: [3/4] Linking dependencies...
5:37:42 PM: warning  > next-plugin-preact@3.0.7 has unmet peer dependency preact-ssr-prepass@>=1.
5:37:42 PM: warning next-plugin-preact > @prefresh/next@1.7.0 has incorrect peer dependency next@^9.4.0 || ^10.0.0 || ^11.0.0 || ^12.0.0.
5:37:42 PM: warning next-plugin-preact > @prefresh/next@1.7.0 has unmet peer dependency webpack@^4.0.0 || ^5.0.0.
5:37:42 PM: warning next-plugin-preact > @prefresh/webpack@3.3.4 has unmet peer dependency @prefresh/babel-plugin@^0.4.0.
5:37:42 PM: warning next-plugin-preact > @prefresh/webpack@3.3.4 has unmet peer dependency webpack@^4.0.0 || ^5.0.0.
5:37:42 PM: warning next-plugin-preact > @prefresh/next > @prefresh/webpack@4.0.0 has unmet peer dependency webpack@^4.0.0 || ^5.0.0.
5:37:42 PM: warning @graphql-codegen/cli > @graphql-tools/code-file-loader > @graphql-tools/graphql-tag-pluck > @babel/plugin-syntax-import-assertions@7.22.5 has unmet peer dependency @babel/core@^7.0.0-0.
5:37:42 PM: warning  > @graphql-codegen/typescript-graphql-request@5.0.0 has unmet peer dependency graphql-tag@^2.0.0.
5:37:42 PM: warning  > @typescript-eslint/eslint-plugin@5.60.1 has unmet peer dependency @typescript-eslint/parser@^5.0.0.
5:37:42 PM: warning Workspaces can only be enabled in private projects.
5:37:42 PM: warning Workspaces can only be enabled in private projects.
5:37:48 PM: [4/4] Building fresh packages...
5:37:48 PM: Done in 44.25s.
5:37:49 PM: npm packages installed using Yarn
5:37:49 PM: Install dependencies script success
5:37:49 PM: Starting build script
5:37:50 PM: Detected 1 framework(s)
5:37:50 PM: next at version 13.4.7
5:37:50 PM: Section completed: initializing
5:37:51 PM: ​
5:37:51 PM: Netlify Build                                                 
5:37:51 PM: ────────────────────────────────────────────────────────────────
5:37:51 PM: ​
5:37:51 PM: ❯ Version
5:37:51 PM:   @netlify/build 29.16.0
5:37:51 PM: ​
5:37:51 PM: ❯ Flags
5:37:51 PM:   baseRelDir: true
5:37:51 PM:   buildId: 64b26850494a770008440e3d
5:37:51 PM:   deployId: 64b26850494a770008440e3f
5:37:51 PM: ​
5:37:51 PM: ❯ Current directory
5:37:51 PM:   /opt/build/repo
5:37:51 PM: ​
5:37:51 PM: ❯ Config file
5:37:51 PM:   No config file was defined: using default values.
5:37:51 PM: ​
5:37:51 PM: ❯ Context
5:37:51 PM:   production
5:37:52 PM: ​
5:37:52 PM: ❯ Installing plugins
5:37:52 PM:    - @netlify/plugin-nextjs@4.39.1
5:38:00 PM: ​
5:38:00 PM: ❯ Using Next.js Runtime - v4.39.1
5:38:02 PM: ​
5:38:02 PM: @netlify/plugin-nextjs (onPreBuild event)                     
5:38:02 PM: ────────────────────────────────────────────────────────────────
5:38:02 PM: ​
5:38:02 PM: No Next.js cache to restore.
5:38:02 PM: Netlify configuration property build.environment.NEXT_PRIVATE_TARGET value changed.
5:38:02 PM: ​
5:38:02 PM: (@netlify/plugin-nextjs onPreBuild completed in 19ms)
5:38:02 PM: ​
5:38:02 PM: Build command from Netlify app                                
5:38:02 PM: ────────────────────────────────────────────────────────────────
5:38:02 PM: ​
5:38:02 PM: $ yarn build
5:38:02 PM: yarn run v1.22.19
5:38:02 PM: $ next build
5:38:02 PM: - warn No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
5:38:02 PM: - info Linting and checking validity of types...
5:38:05 PM: ./src/generated/graphql-request.ts
5:38:05 PM: 802:53  Warning: '_operationName' is defined but never used.  @typescript-eslint/no-unused-vars
5:38:05 PM: 802:69  Warning: '_operationType' is defined but never used.  @typescript-eslint/no-unused-vars
5:38:05 PM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
5:38:05 PM: - info Creating an optimized production build...
5:38:17 PM: - info Compiled successfully
5:38:17 PM: - info Collecting page data...
5:38:22 PM: ClientError: GraphQL Error (Code: 404): {response:{error:<!DOCTYPE html>\n<html lang=\en\>\n<head>\n<meta charset=\utf-8\>\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /</pre>\n</body>\n</html>\n,status:404,headers:{}},request:{query:query ListBlogsWithCatTag {\n  listBlogsWithCatTag {\n    title\n    description\n    body\n    slug\n    _id\n    mtitle\n    imageUri\n    active\n    createdAt\n    updatedAt\n    author {\n      name\n      profile\n    }\n    categories {\n      slug\n      name\n    }\n    tags {\n      slug\n      name\n    }\n  }\n}}}
5:38:22 PM:     at makeRequest (file:///opt/build/repo/node_modules/graphql-request/build/esm/index.js:282:15)
5:38:22 PM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
5:38:22 PM:     at async getStaticPaths (/opt/build/repo/.next/server/pages/blogs/[slug].js:283:44)
5:38:22 PM:     at async buildStaticPaths (/opt/build/repo/node_modules/next/dist/build/utils.js:702:33)
5:38:22 PM:     at async /opt/build/repo/node_modules/next/dist/build/utils.js:1130:113
5:38:22 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:103:20) {
5:38:22 PM:   response: {
5:38:22 PM:     error: '<!DOCTYPE html>\n' +
5:38:22 PM:       '<html lang=en>\n' +
5:38:22 PM:       '<head>\n' +
5:38:22 PM:       '<meta charset=utf-8>\n' +
5:38:22 PM:       '<title>Error</title>\n' +
5:38:22 PM:       '</head>\n' +
5:38:22 PM:       '<body>\n' +
5:38:22 PM:       '<pre>Cannot POST /</pre>\n' +
5:38:22 PM:       '</body>\n' +
5:38:22 PM:       '</html>\n',
5:38:22 PM:     status: 404,
5:38:22 PM:     headers: Headers { [Symbol(map)]: [Object: null prototype] }
5:38:22 PM:   },
5:38:22 PM:   request: {
5:38:22 PM:     query: 'query ListBlogsWithCatTag {\n' +
5:38:22 PM:       '  listBlogsWithCatTag {\n' +
5:38:22 PM:       '    title\n' +
5:38:22 PM:       '    description\n' +
5:38:22 PM:       '    body\n' +
5:38:22 PM:       '    slug\n' +
5:38:22 PM:       '    _id\n' +
5:38:22 PM:       '    mtitle\n' +
5:38:22 PM:       '    imageUri\n' +
5:38:22 PM:       '    active\n' +
5:38:22 PM:       '    createdAt\n' +
5:38:22 PM:       '    updatedAt\n' +
5:38:22 PM:       '    author {\n' +
5:38:22 PM:       '      name\n' +
5:38:22 PM:       '      profile\n' +
5:38:22 PM:       '    }\n' +
5:38:22 PM:       '    categories {\n' +
5:38:22 PM:       '      slug\n' +
5:38:22 PM:       '      name\n' +
5:38:22 PM:       '    }\n' +
5:38:22 PM:       '    tags {\n' +
5:38:22 PM:       '      slug\n' +
5:38:22 PM:       '      name\n' +
5:38:22 PM:       '    }\n' +
5:38:22 PM:       '  }\n' +
5:38:22 PM:       '}',
5:38:22 PM:     variables: undefined
5:38:22 PM:   }
5:38:22 PM: }
5:38:22 PM: > Build error occurred
5:38:22 PM: Error: Failed to collect page data for /blogs/[slug]
5:38:22 PM:     at /opt/build/repo/node_modules/next/dist/build/utils.js:1161:15
5:38:22 PM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
5:38:22 PM:   type: 'Error'
5:38:22 PM: }
5:38:22 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
5:38:22 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
5:38:22 PM: ​
5:38:22 PM: build.command failed                                        
5:38:22 PM: ────────────────────────────────────────────────────────────────
5:38:22 PM: ​
5:38:22 PM:   Error message
5:38:22 PM:   Command failed with exit code 1: yarn build (https://ntl.fyi/exit-code-1)
5:38:22 PM: ​
5:38:22 PM:   Error location
5:38:22 PM:   In Build command from Netlify app:
5:38:22 PM:   yarn build
5:38:22 PM: ​
5:38:22 PM:   Resolved config
5:38:22 PM:   build:
5:38:22 PM:     command: yarn build
5:38:22 PM:     commandOrigin: ui
5:38:22 PM:     environment:
5:38:22 PM:       - GA_TRACKING_ID
5:38:22 PM:       - NEXT_PUBLIC_CLOUDINARY_NAME
5:38:22 PM:       - NEXT_PUBLIC_CLOUDINARY_PRESET
5:38:22 PM:       - NEXT_PUBLIC_CLOUDINARY_URI
5:38:22 PM:       - NEXT_PUBLIC_DISQUS_SHORTNAME
5:38:22 PM:       - NEXT_PUBLIC_GRAPHQL_ENDPOINT
5:38:22 PM:       - NEXT_PRIVATE_TARGET
5:38:22 PM:     publish: /opt/build/repo/.next
5:38:22 PM:     publishOrigin: ui
5:38:22 PM:   plugins:
5:38:22 PM:     - inputs: {}
5:38:22 PM:       origin: ui
5:38:22 PM:       package: '@netlify/plugin-nextjs'
5:38:23 PM: Caching artifacts
5:38:23 PM: Started saving node modules
5:38:23 PM: Finished saving node modules
5:38:23 PM: Started saving build plugins
5:38:23 PM: Finished saving build plugins
5:38:23 PM: Started saving corepack cache
5:38:23 PM: Finished saving corepack cache
5:38:23 PM: Started saving yarn cache
5:38:25 PM: Finished saving yarn cache
5:38:25 PM: Started saving pip cache
5:38:25 PM: Finished saving pip cache
5:38:25 PM: Started saving emacs cask dependencies
5:38:25 PM: Finished saving emacs cask dependencies
5:38:25 PM: Started saving maven dependencies
5:38:25 PM: Finished saving maven dependencies
5:38:25 PM: Started saving boot dependencies
5:38:25 PM: Finished saving boot dependencies
5:38:25 PM: Started saving rust rustup cache
5:38:25 PM: Finished saving rust rustup cache
5:38:25 PM: Started saving go dependencies
5:38:25 PM: Finished saving go dependencies
5:38:27 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:38:27 PM: Failing build: Failed to build site
5:38:27 PM: Finished processing build request in 1m29.721s

And here is my netlify.toml

[build]
  command = "yarn build"
  publish = ".next/"

[[plugins]]
  package = "@netlify/plugin-nextjs"

Where’s your GraphQL server hosted? The 404 is coming from there. This is not a Netlify issue and not something we can help debug. You’d have to check the logs there.

My server hosted on render,and I took you advice checked the server log,there is an unhandled redis connection error,maybe that’s the problem.Thank you.

ahh well thanks so much for coming back and sharing this with the community!

1 Like

At last I found that this problem just because of me forgetting add /graphql after the server endpoint :smiling_face_with_tear:,now it works fine.Thanks for reminding me check the backend log.