Scheduled API route for Next.js cannot find 404

Site name: https://homage-production.netlify.app/

Hello!

I have deployed a scheduled API route for my Next.js site using this documentation

I am scheduling the route for every ten minutes like so…

export const config = {
  type: "experimental-scheduled",
  schedule: "*/10 * * * *",
};

Unfortunately after deploying I am see this error in my function logs:

Sep 28, 12:20:02 PM: INIT_START Runtime Version: nodejs:18.v12	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:0bdff101a7b4e0589af824f244deb93200e4663c2a8d7d0148b76cd00c48777a
Sep 28, 12:20:04 PM: 355429b4 ERROR  MissingStaticPage [Error]: Failed to load static file for page: /404 ENOENT: no such file or directory, open '/var/task/.next/server/pages/404.html'
    at /var/task/node_modules/next/dist/server/require.js:85:19
    at async Object.loadComponentsImpl [as loadComponents] (/var/task/node_modules/next/dist/server/load-components.js:49:26)
    at async NetlifyNextServer.findPageComponentsImpl (/var/task/node_modules/next/dist/server/next-server.js:600:36)
Sep 28, 12:20:04 PM: 355429b4 INFO   [POST] /.netlify/functions/_api_inventory-handler (API)
Sep 28, 12:20:04 PM: 355429b4 Duration: 1220.88 ms	Memory Usage: 123 MB	Init Duration: 497.00 ms
Sep 28, 12:20:04 PM: 213e9e62 ERROR  MissingStaticPage [Error]: Failed to load static file for page: /404 ENOENT: no such file or directory, open '/var/task/.next/server/pages/404.html'
    at /var/task/node_modules/next/dist/server/require.js:85:19
    at async Object.loadComponentsImpl [as loadComponents] (/var/task/node_modules/next/dist/server/load-components.js:49:26)
    at async NetlifyNextServer.findPageComponentsImpl (/var/task/node_modules/next/dist/server/next-server.js:600:36)
Sep 28, 12:20:04 PM: 213e9e62 INFO   [POST] /.netlify/functions/_api_inventory-handler (API)
Sep 28, 12:20:04 PM: 213e9e62 Duration: 6.55 ms	Memory Usage: 124 MB
Sep 28, 12:20:06 PM: 4a9c50b2 ERROR  MissingStaticPage [Error]: Failed to load static file for page: /404 ENOENT: no such file or directory, open '/var/task/.next/server/pages/404.html'
    at /var/task/node_modules/next/dist/server/require.js:85:19
    at async Object.loadComponentsImpl [as loadComponents] (/var/task/node_modules/next/dist/server/load-components.js:49:26)
    at async NetlifyNextServer.findPageComponentsImpl (/var/task/node_modules/next/dist/server/next-server.js:600:36)
Sep 28, 12:20:06 PM: 4a9c50b2 INFO   [POST] /.netlify/functions/_api_inventory-handler (API)
Sep 28, 12:20:06 PM: 4a9c50b2 Duration: 4.59 ms	Memory Usage: 124 MB

I checked my build logs and there is a static 404 page being generated. I am using the default 404 that is provided with Next.js meaning I have not created a custom page appearing in my /pages directory. The logs also show that /api/inventory is being built. I am including the build log here in case it is helpful:

11:55:38 AM: build-image version: 0143b4617dd9b5b3faed2aefa29c54a846e69aae (focal)
11:55:38 AM: buildbot version: 0143b4617dd9b5b3faed2aefa29c54a846e69aae
11:55:38 AM: Fetching cached dependencies
11:55:38 AM: Starting to download cache of 1.2GB
11:55:58 AM: Finished downloading cache in 19.743s
11:55:58 AM: Starting to extract cache
11:56:06 AM: Finished extracting cache in 7.473s
11:56:06 AM: Finished fetching cache in 27.351s
11:56:06 AM: Starting to prepare the repo for build
11:56:06 AM: Preparing Git Reference refs/heads/main
11:56:08 AM: Custom publish path detected. Proceeding with the specified path: "web/.next"
11:56:08 AM: manpath: warning: $PATH not set
11:56:08 AM: Starting to install dependencies
11:56:08 AM: Python version set to 3.8
11:56:08 AM: Attempting Ruby version 2.7.2, read from environment
11:56:09 AM: Using Ruby version 2.7.2
11:56:10 AM: Started restoring cached go cache
11:56:10 AM: Finished restoring cached go cache
11:56:10 AM: go version go1.19.13 linux/amd64
11:56:10 AM: Using PHP version 8.0
11:56:11 AM: Started restoring cached Node.js version
11:56:12 AM: Finished restoring cached Node.js version
11:56:12 AM: v18.18.0 is already installed.
11:56:13 AM: Now using node v18.18.0 (npm v9.8.1)
11:56:13 AM: Enabling Node.js Corepack
11:56:13 AM: Started restoring cached build plugins
11:56:13 AM: Finished restoring cached build plugins
11:56:13 AM: Started restoring cached corepack dependencies
11:56:13 AM: Finished restoring cached corepack dependencies
11:56:13 AM: Started restoring cached yarn cache
11:56:20 AM: Finished restoring cached yarn cache
11:56:20 AM: No yarn workspaces detected
11:56:20 AM: Started restoring cached node modules
11:56:20 AM: Finished restoring cached node modules
11:56:20 AM: Installing npm packages using Yarn version 1.22.19
11:56:21 AM: yarn install v1.22.19
11:56:21 AM: [1/4] Resolving packages...
11:56:21 AM: [2/4] Fetching packages...
11:56:22 AM: warning swr@2.1.0: The engine "pnpm" appears to be invalid.
11:56:22 AM: [3/4] Linking dependencies...
11:56:22 AM: warning " > eslint-config-next@13.2.4" has unmet peer dependency "eslint@^7.23.0 || ^8.0.0".
11:56:22 AM: warning "eslint-config-next > @typescript-eslint/parser@5.56.0" has unmet peer dependency "eslint@^6.0.0 || ^7.0.0 || ^8.0.0".
11:56:22 AM: warning "eslint-config-next > eslint-import-resolver-typescript@3.5.3" has unmet peer dependency "eslint@*".
11:56:22 AM: warning "eslint-config-next > eslint-plugin-import@2.27.5" has unmet peer dependency "eslint@^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8".
11:56:22 AM: warning "eslint-config-next > eslint-plugin-jsx-a11y@6.7.1" has unmet peer dependency "eslint@^3 || ^4 || ^5 || ^6 || ^7 || ^8".
11:56:22 AM: warning "eslint-config-next > eslint-plugin-react@7.32.2" has unmet peer dependency "eslint@^3 || ^4 || ^5 || ^6 || ^7 || ^8".
11:56:22 AM: warning "eslint-config-next > eslint-plugin-react-hooks@4.6.0" has unmet peer dependency "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0".
11:56:22 AM: warning "eslint-config-next > @typescript-eslint/parser > @typescript-eslint/typescript-estree > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
11:56:22 AM: warning " > next-sanity@4.1.5" has unmet peer dependency "@sanity/icons@^2".
11:56:22 AM: warning " > next-sanity@4.1.5" has unmet peer dependency "@sanity/types@^3".
11:56:22 AM: warning " > next-sanity@4.1.5" has unmet peer dependency "@sanity/ui@^1".
11:56:22 AM: warning " > next-sanity@4.1.5" has unmet peer dependency "sanity@^3".
11:56:22 AM: warning " > next-sanity@4.1.5" has unmet peer dependency "styled-components@^5.2".
11:56:22 AM: warning " > next-sanity-image@6.0.0" has unmet peer dependency "@sanity/client@^5.0.0".
11:56:22 AM: warning "use-shopping-cart > react-dom@17.0.2" has incorrect peer dependency "react@17.0.2".
11:56:23 AM: warning "use-shopping-cart > redux-persist@6.0.0" has unmet peer dependency "redux@>4.0.0".
11:56:23 AM: warning "netlify-cli > @netlify/build > ts-node@10.9.1" has unmet peer dependency "@types/node@*".
11:56:25 AM: [4/4] Building fresh packages...
11:56:25 AM: info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it.
11:56:25 AM: [1/4] Resolving packages...
11:56:26 AM: [2/4] Fetching packages...
11:56:26 AM: [3/4] Linking dependencies...
11:56:26 AM: [4/4] Building fresh packages...
11:56:26 AM: success Installed "node-gyp@9.4.0" with binaries:
11:56:26 AM:       - node-gyp
11:56:30 AM: Done in 8.98s.
11:56:30 AM: npm packages installed using Yarn
11:56:30 AM: Install dependencies script success
11:56:30 AM: Starting build script
11:56:31 AM: Detected 1 framework(s)
11:56:31 AM: "next" at version "13.2.4"
11:56:31 AM: Section completed: initializing
11:56:33 AM: ​
11:56:33 AM: Netlify Build                                                 
11:56:33 AM: ────────────────────────────────────────────────────────────────
11:56:33 AM: ​
11:56:33 AM: ❯ Version
11:56:33 AM:   @netlify/build 29.21.1
11:56:33 AM: ​
11:56:33 AM: ❯ Flags
11:56:33 AM:   baseRelDir: true
11:56:33 AM:   buildId: 6515cc29c94fbb0008768e4d
11:56:33 AM:   deployId: 6515cc29c94fbb0008768e4f
11:56:33 AM: ​
11:56:33 AM: ❯ Current directory
11:56:33 AM:   /opt/build/repo/web
11:56:33 AM: ​
11:56:33 AM: ❯ Config file
11:56:33 AM:   /opt/build/repo/web/netlify.toml
11:56:33 AM: ​
11:56:33 AM: ❯ Context
11:56:33 AM:   production
11:56:33 AM: ​
11:56:33 AM: ❯ Using Next.js Runtime - v4.40.1
11:56:34 AM: ​
11:56:34 AM: @netlify/plugin-nextjs (onPreBuild event)                     
11:56:34 AM: ────────────────────────────────────────────────────────────────
11:56:34 AM: ​
11:56:34 AM: Next.js cache restored.
11:56:34 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
11:56:34 AM: ​
11:56:34 AM: (@netlify/plugin-nextjs onPreBuild completed in 153ms)
11:56:34 AM: ​
11:56:34 AM: Build command from Netlify app                                
11:56:34 AM: ────────────────────────────────────────────────────────────────
11:56:34 AM: ​
11:56:34 AM: $ next build
11:56:35 AM: info  - Linting and checking validity of types...
11:56:35 AM: info  - Creating an optimized production build...
11:56:42 AM: info  - Compiled successfully
11:56:42 AM: info  - Collecting page data...
11:56:49 AM: info  - Generating static pages (0/7)
11:56:50 AM: info  - Generating static pages (1/7)
11:56:52 AM: info  - Generating static pages (3/7)
11:56:52 AM: info  - Generating static pages (5/7)
11:56:52 AM: info  - Generating static pages (7/7)
11:56:52 AM: info  - Finalizing page optimization...
11:56:53 AM: Route (pages)                                               Size     First Load JS
11:56:53 AM: ┌ ● / (2808 ms)                                             4.37 kB         431 kB
11:56:53 AM: ├   /_app                                                   0 B             299 kB
11:56:53 AM: ├ ○ /404                                                    184 B           300 kB
11:56:53 AM: ├ λ /api/check                                              0 B             299 kB
11:56:53 AM: ├ λ /api/checkout_sessions/cart                             0 B             299 kB
11:56:53 AM: ├ λ /api/create                                             0 B             299 kB
11:56:53 AM: ├ λ /api/delete                                             0 B             299 kB
11:56:53 AM: ├ λ /api/inventory                                          0 B             299 kB
11:56:53 AM: ├ λ /api/revalidate                                         0 B             299 kB
11:56:53 AM: ├ λ /api/search/index-all                                   0 B             299 kB
11:56:53 AM: ├ λ /api/search/webhook                                     0 B             299 kB
11:56:53 AM: ├ λ /api/update                                             0 B             299 kB
11:56:53 AM: ├ ● /blog/[blog_slug] (2684 ms)                             1.53 kB         429 kB
11:56:53 AM: ├   └ /blog/fake-post (2684 ms)
11:56:53 AM: ├ λ /collections/[collection_slug]                          5.43 kB         429 kB
11:56:53 AM: ├ ● /collections/[collection_slug]/products/[product_slug]  23.4 kB         450 kB
11:56:53 AM: ├ ● /info (2631 ms)                                         3.23 kB         430 kB
11:56:53 AM: ├ ● /our-story (2812 ms)                                    673 B           428 kB
11:56:53 AM: ├ ● /privacy-policy (2426 ms)                               2.28 kB         426 kB
11:56:53 AM: └ λ /search                                                 998 B           425 kB
11:56:53 AM: + First Load JS shared by all                               321 kB
11:56:53 AM:   ├ chunks/framework-73b8966a3c579ab0.js                    45.2 kB
11:56:53 AM:   ├ chunks/main-fbe9c9f0314b4cf5.js                         27.1 kB
11:56:53 AM:   ├ chunks/pages/_app-8105b466040b9c2b.js                   226 kB
11:56:53 AM:   ├ chunks/webpack-6ef43a8d4a395f49.js                      999 B
11:56:53 AM:   └ css/a744e878b759f166.css                                21.2 kB
11:56:53 AM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
11:56:53 AM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
11:56:53 AM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
11:56:53 AM: ​
11:56:53 AM: (build.command completed in 18.1s)
11:56:53 AM: ​
11:56:53 AM: @netlify/plugin-nextjs (onBuild event)                        
11:56:53 AM: ────────────────────────────────────────────────────────────────
11:56:53 AM: ​
11:56:53 AM: Moving static page files to serve from CDN...
11:56:53 AM: Moved 12 files
11:56:53 AM: You are not using Netlify Edge Functions for image format detection. Set env var "NEXT_FORCE_EDGE_IMAGES=true" to enable.
11:56:53 AM: Netlify configuration property "redirects" value changed to [
11:56:53 AM:   { from: "/_next/static/*", to: "/static/:splat", status: 200 },
11:56:53 AM:   {
11:56:53 AM:     from: "/_next/image*",
11:56:53 AM:     query: { url: ":url", w: ":width", q: ":quality" },
11:56:53 AM:     to: "/_ipx/w_:width,q_:quality/:url",
11:56:53 AM:     status: 301
11:56:53 AM:   },
11:56:53 AM:   { from: "/_ipx/*", to: "/.netlify/builders/_ipx", status: 200 },
11:56:53 AM:   { from: "/api/inventory", to: "/404.html", status: 404 },
11:56:53 AM:   {
11:56:53 AM:     from: "/api/*",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/Fbook.png",
11:56:53 AM:     to: "/Fbook.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/Homage-Logo-With-Tagline_205x@2x.avif",
11:56:53 AM:     to: "/Homage-Logo-With-Tagline_205x@2x.avif",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/Insta.png",
11:56:53 AM:     to: "/Insta.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/android-chrome-192x192.png",
11:56:53 AM:     to: "/android-chrome-192x192.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/android-chrome-512x512.png",
11:56:53 AM:     to: "/android-chrome-512x512.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/apple-touch-icon.png",
11:56:53 AM:     to: "/apple-touch-icon.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/blog-lines.png",
11:56:53 AM:     to: "/blog-lines.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/email.png",
11:56:53 AM:     to: "/email.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/facebook.png",
11:56:53 AM:     to: "/facebook.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/favicon-16x16.png",
11:56:53 AM:     to: "/favicon-16x16.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/favicon-32x32.png",
11:56:53 AM:     to: "/favicon-32x32.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/favicon.ico",
11:56:53 AM:     to: "/favicon.ico",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/netlifyformcopy.html",
11:56:53 AM:     to: "/netlifyformcopy.html",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/site.webmanifest",
11:56:53 AM:     to: "/site.webmanifest",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/sms.png",
11:56:53 AM:     to: "/sms.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/twitter.png",
11:56:53 AM:     to: "/twitter.png",
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     status: 200
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/*",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     conditions: { Cookie: [Array] },
11:56:53 AM:     force: true
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/_next/data/KTJVogd_PXwAyQzXHS87h/search.json",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/search",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/_next/data/KTJVogd_PXwAyQzXHS87h/blog/:blog_slug.json",
11:56:53 AM:     to: "/.netlify/builders/___netlify-odb-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/blog/:blog_slug",
11:56:53 AM:     to: "/.netlify/builders/___netlify-odb-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/_next/data/KTJVogd_PXwAyQzXHS87h/collections/:collection_slug.json",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/collections/:collection_slug",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/_next/data/KTJVogd_PXwAyQzXHS87h/collections/:collection_slug/products/:product_slug.json",
11:56:53 AM:     to: "/.netlify/builders/___netlify-odb-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/collections/:collection_slug/products/:product_slug",
11:56:53 AM:     to: "/.netlify/builders/___netlify-odb-handler",
11:56:53 AM:     status: 200,
11:56:53 AM:     force: false
11:56:53 AM:   },
11:56:53 AM:   {
11:56:53 AM:     from: "/*",
11:56:53 AM:     to: "/.netlify/functions/___netlify-handler",
11:56:53 AM:     status: 200
11:56:53 AM:   }
11:56:53 AM: ].
11:56:53 AM: ​
11:56:53 AM: (@netlify/plugin-nextjs onBuild completed in 375ms)
11:56:53 AM: ​
11:56:53 AM: Functions bundling                                            
11:56:53 AM: ────────────────────────────────────────────────────────────────
11:56:53 AM: ​
11:56:53 AM: Packaging Functions from .netlify/functions-internal directory:
11:56:53 AM:  - ___netlify-handler/___netlify-handler.js
11:56:53 AM:  - ___netlify-odb-handler/___netlify-odb-handler.js
11:56:53 AM:  - _api_inventory-handler/_api_inventory-handler.js
11:56:53 AM:  - _ipx/_ipx.js
11:56:53 AM: ​
11:58:16 AM: ​
11:58:16 AM: (Functions bundling completed in 1m 22.8s)
11:58:16 AM: ​
11:58:16 AM: Edge Functions bundling                                       
11:58:16 AM: ────────────────────────────────────────────────────────────────
11:58:16 AM: ​
11:58:16 AM: ​
11:58:16 AM: (Edge Functions bundling completed in 330ms)
11:58:16 AM: ​
11:58:16 AM: @netlify/plugin-nextjs (onPostBuild event)                    
11:58:16 AM: ────────────────────────────────────────────────────────────────
11:58:16 AM: ​
11:58:16 AM: Next.js cache saved.
11:58:16 AM: Using scheduled API routes
11:58:16 AM: These are run on a schedule when deployed to production.
11:58:16 AM: You can test them locally by loading them in your browser but this will not be available when deployed, and any returned value is ignored.
11:58:16 AM: ​
11:58:16 AM: (@netlify/plugin-nextjs onPostBuild completed in 182ms)
11:58:16 AM: ​
11:58:16 AM: Deploy site                                                   
11:58:16 AM: ────────────────────────────────────────────────────────────────
11:58:16 AM: ​
11:58:16 AM: Starting to deploy site from "web/.next"
11:58:16 AM: Calculating files to upload
11:58:17 AM: 13 new files to upload
11:58:17 AM: 4 new functions to upload
11:58:24 AM: Starting post processing
11:58:24 AM: Section completed: deploying
11:58:24 AM: Site deploy was successfully initiated
11:58:24 AM: ​
11:58:24 AM: (Deploy site completed in 8.1s)
11:58:25 AM: Post processing - HTML
11:58:25 AM: Post processing - redirect rules
11:58:25 AM: Post processing - header rules
11:58:25 AM: Post processing done
11:58:25 AM: Section completed: postprocessing
11:58:25 AM: Processing form - contact
11:58:25 AM: Detected form fields:
 - firstname
 - lastname
 - youremail
 - message
11:58:25 AM: ​
11:58:25 AM: Netlify Build Complete                                        
11:58:25 AM: ────────────────────────────────────────────────────────────────
11:58:25 AM: ​
11:58:25 AM: (Netlify Build completed in 1m 51.5s)
11:58:25 AM: Caching artifacts
11:58:25 AM: Started saving node modules
11:58:25 AM: Finished saving node modules
11:58:25 AM: Started saving build plugins
11:58:25 AM: Finished saving build plugins
11:58:25 AM: Started saving corepack cache
11:58:25 AM: Finished saving corepack cache
11:58:25 AM: Started saving yarn cache
11:58:26 AM: Site is live ✨
11:58:26 AM: Scheduling functions: _api_inventory-handler
11:58:30 AM: Finished saving yarn cache
11:58:30 AM: Started saving pip cache
11:58:30 AM: Finished saving pip cache
11:58:30 AM: Started saving emacs cask dependencies
11:58:30 AM: Finished saving emacs cask dependencies
11:58:30 AM: Started saving maven dependencies
11:58:30 AM: Finished saving maven dependencies
11:58:30 AM: Started saving boot dependencies
11:58:30 AM: Finished saving boot dependencies
11:58:30 AM: Started saving rust rustup cache
11:58:30 AM: Finished saving rust rustup cache
11:58:30 AM: Started saving go dependencies
11:58:30 AM: Finished saving go dependencies
11:58:30 AM: Build script success
11:58:30 AM: Section completed: building
11:58:34 AM: Uploading Cache of size 1.2GB
11:58:44 AM: Section completed: cleanup
11:58:44 AM: Finished processing build request in 3m5.37s

I did try to update @netlify/plugin-nextjs. The only thought I have is that I could create a custom 404 page in my /pages directory to get around this error? Is this a known issue? The function schedule is running on time but the data I am attempting to collect in the route is not updating in my CMS. Everything is working in development. Any info would be appreciated thank you.

Hiya @clarity ,

I think that your code may be trying to access some file called literally /404 in the lambda - which of course doesn’t exist. In general your site’s files are not deployed with the lambda, unless you explicitly include them using the included_files directive mentioned here:

If I guess right, your options are either:

  • use something like fetch to access your site to read the file(s) in question
  • return a redirect if you just want to send a 404 - but you wouldn’t do that in a scheduled function since that is not triggered by a browser
  • or include the files as described.

Thanks for your reply. I’m a little confused as to why my code is calling /404 but I’m assuming the problem may have something to do with aforementioned use of the default Next static 404.

Seems like modifying the netlify.toml is my best bet. Would my syntax look like so?

  [functions]
  included_files = ["pages/404.html"]

or ["pages/404"] or ["/404"]

I see that its best to be as specific as possible about what files I’m including. Trying to be as clear as possible before I push. Thanks!

I think you’d want to:

  • copy the /404/index.html file
  • to the folder your function is in
  • as /404.html or maybe plain /404

…but I’m not really sure that would work. I’d instead put some effort into figuring out why your code is trying to access it if I were you. I don’t really have any advice about how to do that…

Hello,

I’m sorry but this is getting a little convoluted. I’ve spent a lot of time trying to see if there is anywhere in my API route that calls a 404 but found nothing.

This is also a bit confusing considering the issue is that my scheduled function is relying on the 404 and I am exporting the config as directed by your documentation. I did not write this function locally in the .netlify/functions folder.

Furthermore it runs contrary to your documentation to manually copy a file to the functions folder even if I did have my function located there. By setting my included_files parameter the system should copy the 404 to the function folder automatically in the function deployment. I tried doing this to no avail.

Can you please investigate this issue a bit further? I have run into similar issues with your functions before.

Any chance this can get elevated or you can let me know if there’s a way I can provide more information that would be helpful? When I visit the API route in my browser it returns a 404 which might be the reason the function is also breaking? Locally everything works fine.

I am listing everything I have tried here:

  • Removing response body and only returning status
  • Removing a POST request to another route.
  • Adding /404 to included pages in netlify.toml functions
  • Removing HTTP method conditions (if POST or if GET)
  • Creating custom 404 page
  • Upgrading netlify/plugin-nextjs
  • Change cron schedule to hourly

I’d suggest using Scheduled Functions outside of Next.js: Scheduled Functions | Netlify Docs.

We released it with Next.js a while back (when Next.js 13 wasn’t a thing) and have been struggling to get Next.js 13 working on Netlify that this “extra” feature is not really a priority to be looked at or fixed right now.

Okay just to be clear are you saying I can set up a Scheduled Function using the documentation you linked to or that your scheduled functions will not work within my Next.js 13 project whatsoever?

They could, but if they don’t, we do not have the bandwidth to investigate why they don’t due to some other priorities for Next.js.

That would most likely work, and if it doesn’t, that’s something we can investigate and fix in a much sooner time.

Thank you for the updated information.

My function is now working correctly following this documentation. In brief, instead of just exporting a config in my Next.js API route, I wrote a function in a dedicated folder that submits a POST request to the route. I am including my code below in case it is helpful to anyone.

export default async (req) => {

  const response = await fetch(`${URL}/api/route`, {
    method: "POST"
  })

  return new Response("Route returned response", { status: response.status })

}

export const config = {
  schedule: "*/10 * * * *"
}