Function ___netlify-server-handler has returned an error: ENOENT: no such file or directory, open '{package directory}/run-config.json'

Hi, my site is elaborate-cactus-b60dfa.

I’ve switched the repo to a monorepo. I’ve moved my application from the root folder to apps/gatographql, including netlify.toml. Following the Monorepo docs, I’ve updated the “packages directory” config in the Build settings, to point to apps/gatographql.

I’ve successfully deployed the app to production (gatographql.com). However, when I do netlify dev in my laptop, I get the following error:

◈ Function ___netlify-server-handler has returned an error: ENOENT: no such file or directory, open '{...}/apps/gatographql/run-config.json'

I’ve also noticed the following:

  • It worked successfully deploying to Netlify, by using @netlify/plugin-nextjs@4.41.3
  • When using the latest version 5.8.1, that same problem happened, and the deployment failed

So I guess there are actually 2 errors (when using a monorepo):

  1. Why plugin-nextjs@4.41.3 fails with netlify dev
  2. Why plugin-nextjs@5.8.1 fails deploying to prod

Please advice. Should I post this as a bug in github.com/opennextjs/opennextjs-netlify? I’ve seen this other bug which may be related.

Thanks

Update: I deleted the .netlify folder from apps/gatographql and now doing netlify dev in my laptop works, using plugin-nextjs@4.41.3. (I guess something was cached from a previous try using v5.8.1).

So the problem happens only with plugin-nextjs@v5.8.1, in all environments: netlify dev and deploying to Netlify.

Hmmmm there’s something else going on. I’ll close this issue, and open a new one.

Posted it as a bug in the repo:

I’d really recommend against polluting the repo without getting a confirmation from support about thhis being a bug. Monorepos work fine (I deploy those on a daily basis).

Furthermore, if there’s an actual issue, us escalating it internally would make an actual difference than a user-submitted bug report that’s not yet confirmed.

Happy to take a look at this if you have a reproduction to share.

Hi @hrishikesh thanks for your help.

Ok, I’ve added a comment on the GitHub issue stating to ignore it for the time being.

The issue is that when doing netlify deploy --build --context deploy-preview with the monorepo:

  • The build part appends the package directory (apps/gatographql). to the destination folder
  • The deploy part does not

Then, it gives error message:

Your publish directory does not contain expected Next.js build output. Please check your build settings

(The apps/gatographql/.next folder was created properly)

The repo for my site (elaborate-cactus-b60dfa) is private, so I replicated the configuration here:

The Build settings in Netlify is this one:

The complete output from running netlify deploy --build --context deploy-preview locally is this one:


Netlify Build                                                 
────────────────────────────────────────────────────────────────

❯ Version
  @netlify/build 29.36.3

❯ Flags
  packagePath: apps/gatographql

❯ Current directory
  /Users/leo/GitRepos/GitHub/Sites/leoloso/gatographql.com

❯ Config file
  /Users/leo/GitRepos/GitHub/Sites/leoloso/gatographql.com/apps/gatographql/netlify.toml

❯ Context
  deploy-preview

❯ Using Next.js Runtime - v5.8.1

Cleaning up leftover files from previous builds               
────────────────────────────────────────────────────────────────


(Pre cleanup completed in 13ms)

@netlify/plugin-nextjs (onPreBuild event)                     
────────────────────────────────────────────────────────────────


(@netlify/plugin-nextjs onPreBuild completed in 137ms)

build.command from netlify.toml                               
────────────────────────────────────────────────────────────────

$ npm run build --prefix apps/gatographql

> gatographql@0.1.0 build
> export $(cat .env | xargs) && NODE_OPTIONS=--max-old-space-size=8192 next build

   ▲ Next.js 14.1.3
   - Environments: .env

   Creating an optimized production build ...
Generated 379 documents in .contentlayer
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (230/230) 
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                                                                             Size     First Load JS
┌ ○ /                                                                                   31.9 kB        1.38 MB
├ ○ /_not-found                                                                         0 B                0 B
├ ○ /about                                                                              2.83 kB         124 kB
├ λ /api/deploy-algolia                                                                 0 B                0 B
├ ○ /architecture                                                                       174 B          84.8 kB
├ ● /architecture/[slug]                                                                158 B           121 kB
├   ├ /architecture/cms-agnosticism
├   ├ /architecture/code-first
├   ├ /architecture/dataloading-engine
├   └ [+12 more paths]
├ ○ /blog                                                                               2.24 kB        1.31 MB
├ ● /blog/[slug]                                                                        1.52 kB         123 kB
├   ├ /blog/introducing-headless-wordpress-without-wordpress
├   ├ /blog/released-v70-to-power-standalone-plugins
├   ├ /blog/gatographql-gets-streamlined
├   └ [+46 more paths]
├ ○ /comparisons                                                                        4.6 kB          101 kB
├ ● /comparisons/[slug]                                                                 2.68 kB         124 kB
├   ├ /comparisons/gatographql-vs-wp-rest-api
├   └ /comparisons/gatographql-vs-wpgraphql
├ ○ /contact                                                                            3.27 kB          93 kB
├ ○ /demos                                                                              3.84 kB        1.31 MB
├ ● /demos/[slug]                                                                       6.46 kB         122 kB
├   ├ /demos/automatically-importing-new-posts-from-any-wordpress-rss-feed-daily
├   ├ /demos/automatically-sending-an-email-to-all-subscribers-notifying-of-a-new-post
├   ├ /demos/automatically-sync-post-featured-image-for-polylang
├   └ [+13 more paths]
├ ○ /developers                                                                         1.13 kB         122 kB
├ ○ /docs                                                                               174 B          84.8 kB
├ ○ /download                                                                           1.13 kB         122 kB
├ ○ /extensions                                                                         793 B          1.34 MB
├ ○ /extensions-reference                                                               174 B          84.8 kB
├ λ /extensions-reference/[topic]                                                       174 B          84.8 kB
├ ● /extensions-reference/[topic]/[slug]                                                158 B           121 kB
├ ● /extensions/[slug]                                                                  4.89 kB        1.34 MB
├   ├ /extensions/access-control
├   ├ /extensions/caching
├   ├ /extensions/custom-endpoints
├   └ [+7 more paths]
├ ○ /extensions/opengraph-image-1ptgva.png                                              0 B                0 B
├ ○ /extensions/twitter-image-1ptgva.png                                                0 B                0 B
├ ○ /features                                                                           2.38 kB        98.9 kB
├ ● /features/[slug]                                                                    7.38 kB         123 kB
├   ├ /features/access-control
├   ├ /features/api-hierarchy-and-endpoint-management
├   ├ /features/custom-endpoints
├   └ [+12 more paths]
├ ○ /features/opengraph-image-q698t4.png                                                0 B                0 B
├ ○ /features/twitter-image-q698t4.png                                                  0 B                0 B
├ ○ /guides                                                                             174 B          84.8 kB
├ λ /guides/[topic]                                                                     174 B          84.8 kB
├ ● /guides/[topic]/[slug]                                                              158 B           121 kB
├ ○ /highlights                                                                         4.26 kB         134 kB
├ ○ /howdy                                                                              5.48 kB         121 kB
├ ○ /library                                                                            174 B          84.8 kB
├ ● /library/[slug]                                                                     158 B           121 kB
├   ├ /library/add-a-mandatory-comments-block-to-post
├   ├ /library/add-missing-links-in-post
├   ├ /library/augment-data-from-an-external-api
├   └ [+49 more paths]
├ ○ /newsletter                                                                         3.75 kB        93.5 kB
├ ○ /opengraph-image.png                                                                0 B                0 B
├ ○ /pricing                                                                            395 B          1.32 MB
├ ○ /refund-policy                                                                      6.13 kB         122 kB
├ ○ /robots.txt                                                                         0 B                0 B
├ ○ /shop                                                                               174 B          84.8 kB
├ ○ /shop/customer-portal                                                               158 B           121 kB
├ ○ /shop/my-orders                                                                     158 B           121 kB
├ ○ /shop/success                                                                       1.13 kB         122 kB
├ ○ /sitemap.xml                                                                        0 B                0 B
├ ○ /slides                                                                             174 B          84.8 kB
├ ○ /slides/cover                                                                       3.66 kB        93.4 kB
├ λ /slides/extension-cover/[slug]                                                      4.15 kB        93.9 kB
├ ○ /specials                                                                           174 B          84.8 kB
├ ○ /specials/wpbuilds                                                                  158 B           121 kB
├ ○ /support                                                                            3.12 kB        92.8 kB
├ ○ /tutorial                                                                           174 B          84.8 kB
├ ● /tutorial/[slug]                                                                    158 B           121 kB
├   ├ /tutorial/adapting-content-in-bulk
├   ├ /tutorial/automatically-adding-a-mandatory-block
├   ├ /tutorial/automatically-sending-newsletter-subscribers-from-instawp-to-mailchimp
├   └ [+26 more paths]
└ ○ /twitter-image.png                                                                  0 B                0 B
+ First Load JS shared by all                                                           84.7 kB
  ├ chunks/1dd3208c-150aa526550611f4.js                                                 53.4 kB
  ├ chunks/9997-9539fc6784a82a39.js                                                     29.2 kB
  └ other shared chunks (total)                                                         2.07 kB


○  (Static)   prerendered as static content
●  (SSG)      prerendered as static HTML (uses getStaticProps)
λ  (Dynamic)  server-rendered on demand using Node.js


(build.command completed in 28.6s)

@netlify/plugin-nextjs (onBuild event)                        
────────────────────────────────────────────────────────────────


@netlify/plugin-nextjs (onEnd event)                          
────────────────────────────────────────────────────────────────


(@netlify/plugin-nextjs onEnd completed in 6ms)

Save updated config                                           
────────────────────────────────────────────────────────────────


(options.onEnd completed in 4ms)

Plugin "@netlify/plugin-nextjs" failed                        
────────────────────────────────────────────────────────────────

  Error message
  Error: Your publish directory does not contain expected Next.js build output. Please check your build settings

  Plugin details
  Package:        @netlify/plugin-nextjs
  Version:        5.8.1
  Repository:     git+https://github.com/netlify/next-runtime.git
  npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
  Report issues:  https://github.com/netlify/next-runtime/issues

  Error location
  In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app

  Resolved config
  build:
    command: npm run build --prefix apps/gatographql
    commandOrigin: config
    environment:
      - NODE_OPTIONS
    publish: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatographql.com/.next
    publishOrigin: config
  plugins:
    - inputs: {}
      origin: ui
      package: '@netlify/plugin-nextjs'

Notice that the publish var was resolved to /Users/leo/GitRepos/GitHub/Sites/leoloso/gatographql.com/.next, but it should be /Users/leo/GitRepos/GitHub/Sites/leoloso/gatographql.com/apps/gatographql/.next (the package directory apps/gatographql is missing).

Also, removing dependency "next": "^14.1.3" will then install runtime @netlify/plugin-nextjs@4.41.3, and then it works fine

I think, the correct command to deploy is:

netlify deploy --build --context deploy-preview --filter gatographql

In your app/gatographql/netlify.toml, you should have:

[build]
  command = "npm run build -w gatographql"
  publish = "./apps/gatographql/.next/"
  [build.environment]
    NODE_OPTIONS = "--max-old-space-size=8192"

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

Thanks @hrishikesh I added your changes, but now it fails with a different error message:

Plugin "@netlify/plugin-nextjs" failed                        
────────────────────────────────────────────────────────────────

  Error message
  Error: Failed publishing static content

  Plugin details
  Package:        @netlify/plugin-nextjs
  Version:        5.8.1
  Repository:     git+https://github.com/netlify/next-runtime.git
  npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
  Report issues:  https://github.com/netlify/next-runtime/issues

  Error location
  In "onPostBuild" event in "@netlify/plugin-nextjs" from netlify.toml and package.json

  Resolved config
  build:
    base: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql
    command: npm run build -w gatographql
    commandOrigin: config
    environment:
      - NODE_OPTIONS
    publish: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/apps/gatographql/.next
    publishOrigin: config

Notice it says:

publish: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/apps/gatographql/.next

…so apps/gatographql/apps/gatographql/ is duplicated…

Btw, I’ve removed the “Package directory” value from the Build settings in Netlify, yet it still says:

❯ Flags
  packagePath: apps/gatographql

Is that right?

Btw2, running netlify dev --filter gatographql works well.


Full log:

Netlify Build                                                 
────────────────────────────────────────────────────────────────

❯ Version
  @netlify/build 29.36.3

❯ Flags
  packagePath: apps/gatographql

❯ Current directory
  /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites

❯ Config file
  /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/netlify.toml

❯ Context
  deploy-preview

❯ Using Next.js Runtime - v5.8.1

@netlify/plugin-nextjs (onPreBuild event)                     
────────────────────────────────────────────────────────────────


(@netlify/plugin-nextjs onPreBuild completed in 6ms)

build.command from netlify.toml                               
────────────────────────────────────────────────────────────────

$ npm run build -w gatographql

> gatographql@0.1.0 build
> export $(cat .env | xargs) && NODE_OPTIONS=--max-old-space-size=8192 next build

  ▲ Next.js 14.2.18
  - Environments: .env

   Creating an optimized production build ...
Generated 378 documents in .contentlayer
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
 ✓ Generating static pages (230/230)
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (app)                                                                             Size     First Load JS
┌ ○ /                                                                                   32.7 kB        1.39 MB
├ ○ /_not-found                                                                         178 B          87.5 kB
├ ○ /about                                                                              3.1 kB          139 kB
├ ƒ /api/deploy-algolia                                                                 0 B                0 B
├ ○ /architecture                                                                       178 B          87.5 kB
├ ● /architecture/[slug]                                                                157 B           124 kB
├   ├ /architecture/cms-agnosticism
├   ├ /architecture/code-first
├   ├ /architecture/dataloading-engine
├   └ [+12 more paths]
├ ○ /blog                                                                               4.45 kB        1.31 MB
├ ● /blog/[slug]                                                                        1.37 kB         128 kB
├   ├ /blog/introducing-headless-wordpress-without-wordpress
├   ├ /blog/released-v70-to-power-standalone-plugins
├   ├ /blog/gatographql-gets-streamlined
├   └ [+46 more paths]
├ ○ /comparisons                                                                        3.67 kB         116 kB
├ ● /comparisons/[slug]                                                                 4.91 kB         137 kB
├   ├ /comparisons/gatographql-vs-wp-rest-api
├   └ /comparisons/gatographql-vs-wpgraphql
├ ○ /contact                                                                            3.44 kB        95.9 kB
├ ○ /demos                                                                              6.42 kB        1.31 MB
├ ● /demos/[slug]                                                                       5.79 kB         129 kB
├   ├ /demos/automatically-importing-new-posts-from-any-wordpress-rss-feed-daily
├   ├ /demos/automatically-sending-an-email-to-all-subscribers-notifying-of-a-new-post
├   ├ /demos/automatically-sync-post-featured-image-for-polylang
├   └ [+13 more paths]
├ ○ /developers                                                                         257 B           134 kB
├ ○ /docs                                                                               178 B          87.5 kB
├ ○ /download                                                                           257 B           134 kB
├ ○ /extensions                                                                         4.28 kB        1.36 MB
├ ○ /extensions-reference                                                               178 B          87.5 kB
├ ƒ /extensions-reference/[topic]                                                       178 B          87.5 kB
├ ● /extensions-reference/[topic]/[slug]                                                157 B           124 kB
├ ● /extensions/[slug]                                                                  5.03 kB        1.36 MB
├   ├ /extensions/access-control
├   ├ /extensions/caching
├   ├ /extensions/custom-endpoints
├   └ [+7 more paths]
├ ○ /extensions/opengraph-image-1ptgva.png                                              0 B                0 B
├ ○ /extensions/twitter-image-1ptgva.png                                                0 B                0 B
├ ○ /features                                                                           5.79 kB         114 kB
├ ● /features/[slug]                                                                    5.57 kB         138 kB
├   ├ /features/access-control
├   ├ /features/api-hierarchy-and-endpoint-management
├   ├ /features/custom-endpoints
├   └ [+12 more paths]
├ ○ /features/opengraph-image-q698t4.png                                                0 B                0 B
├ ○ /features/twitter-image-q698t4.png                                                  0 B                0 B
├ ○ /guides                                                                             178 B          87.5 kB
├ ƒ /guides/[topic]                                                                     178 B          87.5 kB
├ ● /guides/[topic]/[slug]                                                              157 B           124 kB
├ ○ /highlights                                                                         6.1 kB          138 kB
├ ○ /howdy                                                                              8.25 kB         134 kB
├ ○ /library                                                                            178 B          87.5 kB
├ ● /library/[slug]                                                                     156 B           124 kB
├   ├ /library/add-a-mandatory-comments-block-to-post
├   ├ /library/add-missing-links-in-post
├   ├ /library/augment-data-from-an-external-api
├   └ [+49 more paths]
├ ○ /newsletter                                                                         416 B          96.3 kB
├ ○ /opengraph-image.png                                                                0 B                0 B
├ ○ /pricing                                                                            282 B          1.34 MB
├ ○ /refund-policy                                                                      5.08 kB         124 kB
├ ○ /robots.txt                                                                         0 B                0 B
├ ○ /shop                                                                               178 B          87.5 kB
├ ○ /shop/customer-portal                                                               157 B           123 kB
├ ○ /shop/my-orders                                                                     157 B           123 kB
├ ○ /shop/success                                                                       257 B           134 kB
├ ○ /sitemap.xml                                                                        0 B                0 B
├ ○ /slides                                                                             178 B          87.5 kB
├ ○ /slides/cover                                                                       4.28 kB        96.7 kB
├ ƒ /slides/extension-cover/[slug]                                                      4.71 kB        97.2 kB
├ ○ /specials                                                                           178 B          87.5 kB
├ ○ /specials/wpbuilds                                                                  4.75 kB         133 kB
├ ○ /support                                                                            3.3 kB         95.7 kB
├ ○ /tutorial                                                                           178 B          87.5 kB
├ ● /tutorial/[slug]                                                                    157 B           124 kB
├   ├ /tutorial/adapting-content-in-bulk
├   ├ /tutorial/automatically-adding-a-mandatory-block
├   ├ /tutorial/automatically-sending-newsletter-subscribers-from-instawp-to-mailchimp
├   └ [+26 more paths]
└ ○ /twitter-image.png                                                                  0 B                0 B
+ First Load JS shared by all                                                           87.3 kB
  ├ chunks/1528-fdcf07ae2065d021.js                                                     31.7 kB
  ├ chunks/1dd3208c-fc3e284b884115f7.js                                                 53.6 kB
  └ other shared chunks (total)                                                         2 kB


○  (Static)   prerendered as static content
●  (SSG)      prerendered as static HTML (uses getStaticProps)
ƒ  (Dynamic)  server-rendered on demand


(build.command completed in 59.7s)

@netlify/plugin-nextjs (onBuild event)                        
────────────────────────────────────────────────────────────────


(@netlify/plugin-nextjs onBuild completed in 43.5s)

Functions bundling                                            
────────────────────────────────────────────────────────────────

Packaging Functions from apps/gatographql/.netlify/functions-internal directory:
 - ___netlify-server-handler/___netlify-server-handler.mjs


(Functions bundling completed in 1.2s)

Edge Functions bundling                                       
────────────────────────────────────────────────────────────────


(Edge Functions bundling completed in 368ms)

@netlify/plugin-nextjs (onPostBuild event)                    
────────────────────────────────────────────────────────────────


@netlify/plugin-nextjs (onEnd event)                          
────────────────────────────────────────────────────────────────


(@netlify/plugin-nextjs onEnd completed in 4ms)

Save updated config                                           
────────────────────────────────────────────────────────────────


(options.onEnd completed in 4ms)

Plugin "@netlify/plugin-nextjs" failed                        
────────────────────────────────────────────────────────────────

  Error message
  Error: Failed publishing static content

  Plugin details
  Package:        @netlify/plugin-nextjs
  Version:        5.8.1
  Repository:     git+https://github.com/netlify/next-runtime.git
  npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
  Report issues:  https://github.com/netlify/next-runtime/issues

  Error location
  In "onPostBuild" event in "@netlify/plugin-nextjs" from netlify.toml and package.json

  Resolved config
  build:
    base: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql
    command: npm run build -w gatographql
    commandOrigin: config
    environment:
      - NODE_OPTIONS
    publish: /Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/apps/gatographql/.next
    publishOrigin: config
  plugins:
    - inputs: {}
      origin: config
      package: '@netlify/plugin-nextjs'
  redirectsOrigin: inline

Unfortunately, that error is vague and comes from: opennextjs-netlify/src/build/content/static.ts at 00e3a4be19bf8428ea6ce1ed2ae74a8ac8375532 · opennextjs/opennextjs-netlify. So it can fail in either of those lines and return the same issue.

Since you’re building locally, could you modify the file in node_modules directory to log out the error which might have additional details?

Hi @hrishikesh I modified that line to:

ctx.failBuild("Failed publishing static content (Modified output)", error);

Now the output printed:

Plugin "@netlify/plugin-nextjs" failed                        
────────────────────────────────────────────────────────────────

  Error message
  Error: Failed publishing static content (Modified output)
  ENOENT: no such file or directory, rename '/Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/apps/gatographql/.next' -> '/Users/leo/GitRepos/GitHub/Sites/leoloso/gatowebsites/apps/gatographql/.netlify/.next'