Can't deploy Sanity and NextJs starter template

I’m trying to deploy the NextJS & Sanity starter template in Netlify. The starter template can be found Clean template

I’m trying to install the whole repo in netlify, in a second stadium I want to separate the studio (the studio is already deployed via Sanity and thus not needed and will only take additional time for loading).

The structure is not changed and I only added a netlify.toml

[build]
  command = "npm install && npm run build"
  publish = ".next"
  base = "nextjs-app"

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

The .toml file is located in the nextjs-app folder.
The error from the deploy is:

Plugin "@netlify/plugin-nextjs" internal error                
────────────────────────────────────────────────────────────────
​
  Error message
  Error: ENOENT: no such file or directory, scandir '/Users/uesername/my-website/nextjs-app/node_modules'
​
  Plugin details
  Package:        @netlify/plugin-nextjs
  Version:        5.9.2
  Repository:     git+https://github.com/opennextjs/opennextjs-netlify.git
  npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
  Report issues:  https://github.com/opennextjs/opennextjs-netlify/issues
​
  Error location
  In "onBuild" event in "@netlify/plugin-nextjs" from netlify.toml and package.json
​
  Error properties
  {
    errno: -2,
    code: 'ENOENT',
    syscall: 'scandir',
    path: '/Users/username/my-website/nextjs-app/node_modules'
  }
​
  Resolved config
  build:
    base: /Users/username/my-website/nextjs-app
    command: npm install && npm run build
    commandOrigin: config
    publish: /Users/username/my-website/nextjs-app/.next
    publishOrigin: config
  plugins:
    - inputs: {}
      origin: config
      package: '@netlify/plugin-nextjs'

Your netlify.toml needs to exist in nextjs-app folder. Then do the following:

  • Remove base.
  • Change command to npm run build --w=nextjs-app. The string nextjs-app might have to be changed if you’ve changed the workspaces config in the root package.json and/or the name field in nextjs-app/package.json.
  • Then, in Netlify CLI, run the following command:
netlify deploy --build --filter=nextjs-app

Hmm seems like this is not the solution. My .toml looks like

[build]
  publish = ".next"
  command = "npm run build --w=nextjs-app"

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

I tried the command you suggested from the root but I’m getting this error

  Error: Your publish directory was not found at: /Users/username/my-website/nextjs-app/nextjs-app/.next. Please check your build settings

Where does the double nextjs-app directory come from?

I tried the command

netlify deploy --build --prod

from the nextjs-app directory, but I get the same error message.

When using the following command from the root and selecting the nextjs-app workspace

netlify deploy --prod

The deploy is succesfully but the page stills returns a 404, this is perhabs explainable because the production deploys on the dashboard doesn’t state there isn’t a successfully deploy

While the cli says

✔ Deploy is live!

Are you sure there isn’t a base directory set?

Sorry, publish needs to be: nextjs-app/.next along with whatever I said above.

This gives me the same error

[build]
  publish = "nextjs-app/.next"
  command = "npm run build --w=nextjs-app"

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

Error: Your publish directory was not found at: /Users/myuser/my-website/nextjs-app/nextjs-app/.next. Please check your build settings

Also setting the base directory doesn’t work, a fresh repo and clean install doesn’t solve the problem. I suspect that the problem is in the toml config