Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using the Next 13 app directory on Netlify #1724

Unanswered
ascorbic asked this question in Q&A
Discussion options

If you update your site to Next 13, it will work on Netlify right away. All the stable features work out of the box with no changes required on your part when using the latest Netlify Next.js runtime. If you have manually installed the Netlify Next.js runtime in your package.json you will need to upgrade it, but for everyone else it will upgrade you automatically on your next deploy. However this does not include the new experimental app directory features. This is currently pre-release and should not be used for production.

While deploying app directory sites to Netlify is still experimental, it already supports many of the most interesting new features, including React Server Components and streaming HTML using the edge runtime. Pages that use the edge runtime are automatically deployed to Netlify Edge Functions.

This topic is for discussion of the use of app directory features, not general Next 13 topics. If you encounter a problem with an existing feature such as the pages directory or middleware, then open an issue rather than commenting here.

Update: you no longer need to install a special version of the runtime - the auto-installed version has appDir support enabled, though it is still experimental

Known issues

You must be logged in to vote

Replies: 17 comments 39 replies

Comment options

Seems to break with the latest version of nextjs 13.0.3. Getting an internal server error 500.

@ascorbic should we continue to use the next js runtime at 4.29.1 or should we lock to 4.28.4-appdir.0 for now?

You must be logged in to vote
4 replies
Comment options

I will be putting a new version of the appdir branch out tomorrow

Comment options

@ascorbic thanks! Appreciate it :)

Comment options

@ascorbic QQ is there anyway to have the runtime auto upgrade only to the appDir versions (I know one usually uses ^ to indicate versions higher than this)

Comment options

If you explicitly set the dependency to "@netlify/plugin-nextjs": "appdir" then that should do it

Comment options

Hello guys 👋
So, I'm trying to deploy my NextJS 13 test app to Netlify (of course using appdir experimental feature) and weirdly enough all my routes navigation is turned into a hard page refresh 🤔 Is that expected?
Here is the preview of the app.
If you click on "Hello" text it should redirect you to the hello page using a hard page refresh.

You must be logged in to vote
7 replies
Comment options

Thanks, I am also having the same issue occur, excited for this patch!

Comment options

I too seem to be having the same issue

Comment options

I’m also seeing the same issue of complete page re-renders when navigating with the component. Looking forward for a fix as well! 🤓

Comment options

Just tried the app on Vercel, and seems to be fine. So it does at least appear to be related to Netlify in particular.

Comment options

Any update to fix this behaviour? 😊

Comment options

Not sure if this is a Netlify issue or a problem with my own code, but I keep getting a 500 Internal Server error when trying to fetch() data. I've described my issue in detail on StackOverflow.

You must be logged in to vote
2 replies
Comment options

Hi. I've replied on SO, but looking at your logs you're getting the error "Error: Page changed from static to dynamic at runtime /team/1, see more here https://nextjs.org/docs/messages/app-static-to-dynamic-error"

Comment options

This solved my issue. Thank you so much for the tips!

Comment options

It seems that Next.js 13's loading UI doesn't work with Netlify (i.e. React Suspense component.)

My suspense component works fine locally with npm run dev and ntl dev, but it doesn't work when deployed to Netlify. One clear way to see this is by using the React developer tools Chrome extension.

ntl dev
Screenshot 2023年01月26日 at 3 50 05 PM

https://loading--dundermifflininc.netlify.app/team
Screenshot 2023年01月26日 at 3 50 39 PM

You must be logged in to vote
3 replies
Comment options

I'll take a look, thanks. Could be because we don't support streaming from the Node runtime?

Comment options

Thanks! Sounds like a reasonable hypothesis, but a bit over my pay grade at this time.

Comment options

I have noticed this issue as well. Commenting to hopefully stay in the loop. Cheers!

Comment options

Someone using appDir and trailingSlash with nextjs@13.1.6? Opening the url www.example.com/blog/article-a/ results in a redirect to www.example.com/blog/article-a

I've also deployed the same site to vercel and there trailingSlash is respected. I get no redirect.

Is this a known issue?

You must be logged in to vote
0 replies
Comment options

Issue: 500 Internal Server Error when deploying Next 13.4 with embed sanity studio on Netlify.

Adding an embed Sanity studio on Next 13.4. causes "500: Internal Server Error". The problem seems to be specifically related to the serverActions in Next.js 13.4, as the application works fine locally and on previous versions (e.g., 13.3) on the production.

Here is the log on Netlify Functions:

May 9, 12:02:35 PM: c0984344 ERROR Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.jsonMay 9, 12:02:35 PM: c0984344 ERROR at new NodeError (node:internal/errors:387:5)May 9, 12:02:35 PM: c0984344 ERROR at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)May 9, 12:02:35 PM: c0984344 ERROR at packageExportsResolve (node:internal/modules/esm/resolve:649:3)May 9, 12:02:35 PM: c0984344 ERROR at resolveExports (node:internal/modules/cjs/loader:554:36)May 9, 12:02:35 PM: c0984344 ERROR at Function.Module._findPath (node:internal/modules/cjs/loader:594:31)May 9, 12:02:35 PM: c0984344 ERROR at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1012:27)May 9, 12:02:35 PM: c0984344 ERROR at /var/task/node_modules/next/dist/server/require-hook.js:180:36May 9, 12:02:35 PM: c0984344 ERROR at Function.Module._load (node:internal/modules/cjs/loader:871:27)May 9, 12:02:35 PM: c0984344 ERROR at Module.require (node:internal/modules/cjs/loader:1098:19)May 9, 12:02:35 PM: c0984344 ERROR at require (node:internal/modules/cjs/helpers:108:18) {May 9, 12:02:35 PM: c0984344 ERROR code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'May 9, 12:02:35 PM: c0984344 ERROR }

As a temporary workaround, setting the environment variable "__NEXT_PRIVATE_PREBUNDLED_REACT=next" resolved the issue for others. However, Netlify does not allow this particular environment variable to be set due to the prefix of (_).

During investigation, I came across a discussion thread in the Netlify Support Forums that addresses a similar error: Netlify Support Forums Thread.

Additionally, I noticed that there is a pull request in the Next.js GitHub repository that appears to address similar issue specifically for custom servers. It seems to have been fixed and merged on v13.4.0 but many others as well as I'm still getting the error. This might just be an issue with Next itself. Just wanted to point it for someone from Netlify to look into. Next.js PR.

You must be logged in to vote
5 replies
Comment options

@sadhikari1r, we're currently upgrading to 13.4 in the Next.js runtime. You can follow along here, #2080

Comment options

Everything was merged and is currently rolling out. It'll be available to everyone by the end of the week. See https://github.com/netlify/next-runtime/releases/tag/plugin-nextjs-v4.38.0

Comment options

How can I explicitly define that Netlify should use v4.38.0 next.js runtime?

Comment options

The latest runtime still doesn't resolve this issue. I have an app running on 13.4 and still get this error with group routes i.e. app/(studio)/admin/[[...index]]/page.tsx (current sanity studio path with catchall route). I assumed that there's no way to manually change Nextjs runtime in Netlify and that it's updated automatically to the latest version.

Is there something we're missing?

Comment options

@j-hit you should be able to via toml and nextjs plugin (ref the plugin readme). However, this should be automatically updated via Netlify UI.


Just found this related support article where this problem is still present and being worked on.

Comment options

Hi! I am trying to deploy a next 13 app using 'app' router to Netlify. I added a 'not-found.js' to the 'app' directory to create my custom 404 page so that it will be shown when user visit any invalid URL .

I tried to create a repo for testing with just the starter file (npx create-next-app@latest). Without 'not-found.js', the Next default 404 page would be shown when I went to an invalid URL (https://647825f32dfd7e319f25f51d--regal-pika-910873.netlify.app/unkown):
image

However, when I added the 'not-found.js' to 'app' directory and visited an invalid URL, the custom 404 page could not be shown. Instead, "Internal Server Error" was shown (https://647826e083bb9900089436a2--regal-pika-910873.netlify.app/unkown):
image

I have also tried to deploy a next app using 'page' router and added '404.js' to 'page' directory and it works well(https://amazing-quokka-cb8229.netlify.app/unknown):
image

Is there any solution if I would like creating my custom page with 'app' directory? Thank you.

You must be logged in to vote
2 replies
Comment options

Is there any word on this? I'm having the same issue and I can't seem to figure it out.

Comment options

same here, I am looking out for a solution to this issue

Comment options

When deploying a Next.js 13.4.4 app to Netlify I had some issues.

At first I thought the deployment worked but I got the Netlify 404 page when I went to the site's URL.

In Netlify the build was not executed, only the post-processing stage was executed.
image

For it to work I just had to add the following to a netlify.toml file in the root of the repo.

[build]
 publish = ".next"

For full context my .gitlab-ci.yml file looks like this.

stages:
 - build
 - deploy
build-app:
 stage: build
 image: node:16
 script:
 - npm install
 - npm run build
 artifacts:
 paths:
 - .next/
netlify:
 stage: deploy
 image: node:16
 script:
 - npm install -g netlify-cli
 - netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --build --prod --dir=.next
 only:
 - main
You must be logged in to vote
0 replies
Comment options

Hi! Dynamic routes (generated from mdx files) do not work with netlify form actions.
If such routes are used in the form action field, it results in a timeout:
CleanShot 2023年06月16日 at 22 34 07@2x

The form submit works if the same page is created (as a directory under the app).

You must be logged in to vote
1 reply
Comment options

hi @norberthnd, we'd need to discuss a few more details to diagnose the problem here and it would be great if you could open a GitHub issue or get in touch at https://www.netlify.com/support/

Comment options

Hi there.

I just tested out some changes on a preview deployment and the serverless function seems to be crashing and I have no idea why.

Screenshot 2023年06月21日 at 16 01 41
Jun 21, 03:59:26 PM: 2023年06月21日T13:59:26.108Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Error","errorMessage":"Could not find Next.js server","stack":["Error: Could not find Next.js server"," at Object.<anonymous> (/var/task/apps/bikeworld/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:2:9)"," at Module._compile (node:internal/modules/cjs/loader:1196:14)"," at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)"," at Module.load (node:internal/modules/cjs/loader:1074:32)"," at Function.Module._load (node:internal/modules/cjs/loader:909:12)"," at Module.require (node:internal/modules/cjs/loader:1098:19)"," at require (node:internal/modules/cjs/helpers:108:18)"," at Object.<anonymous> (/var/task/___netlify-handler.js:1:18)"," at Module._compile (node:internal/modules/cjs/loader:1196:14)"," at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)"]}

https://14-134258--bikeworldmvp.netlify.app/.netlify/functions/___netlify-handler

What more information do you need to help me figure out why this is happening?

You must be logged in to vote
2 replies
Comment options

If my memory serves me correctly, I encountered an error like this too, but my app worked fine locally. So, I tried deploying to Vercel and it worked.

Comment options

Yep, switching to Vercel also fixed this issue for us.

Comment options

You must be logged in to vote
2 replies
Comment options

sorry you are running into this issue, @mushfiqueyeasir, we have a fix rolling out from Monday #2188

Comment options

Was this fixed? I'm getting the same error but the message refers to react instead of react-dom.

Comment options

Same issue of page reloading with app routing

You must be logged in to vote
0 replies
Comment options

Screenshot 2023年08月22日 at 12 45 51 PM

Got error 500 when refreshing a shop/[bundleId] page on this minimal reproduction repo: https://github.com/DWboutin/test-routing

You must be logged in to vote
9 replies
Comment options

Any updates or solutions which do not include migrating to Vercel?

Comment options

Any solutions!!

Comment options

There is a very very very long discussion held on the Netlify forum. I'll just link the solution which worked for me: https://answers.netlify.com/t/server-edge-not-defined-error-on-nextjs-ssr-functions-cause-site-to-return-500-errors/91793/127

In a nutshell:

  1. npm install next@13.4.9
  2. npm install @netlify/plugin-nextjs@4.40.1
  3. add the experimental appDir: true flag to next.config,js
module.exports = {
 experimental: {
 appDir: true,
 },
}

Let me know if this works for you 👏🤞

Comment options

Updated Next.js to last version 13.5.2, it is fixed.🚀

Comment options

@suhayp-gamma what is fixed? I am using 13.5.2 and it is not working without installing any plugin.

Comment options

Static Images wont load on Netlify when they load on Vercel properly

image
You must be logged in to vote
0 replies
Comment options

Updated Next.js to last version 13.5.2, it is fixed.🚀

You must be logged in to vote
0 replies
Comment options

I am trying to deploy Next.js 13.5.2 App but still get the following:

image

I am using the app router and tried to deploy with GitLab integration. In the deploy logs in Netlify everything was "green" and complete.

You must be logged in to vote
1 reply
Comment options

@ascorbic could you fix it?

Comment options

Does anybody know if dynamicParams still is not supported?

You must be logged in to vote
1 reply
Comment options

Seems like it is not supported yet. Didn't work for me as of today.

I needed dynamicParams = false to return 404s for dynamic pages that are only SSG (no ISR). I was able to work around it by having my data fetching functions return null at runtime (as opposed to return the real data at build time for SSG) and the pages handle null and redirect to 404.

if (data === null) {
 redirect('/404.html');
 }

It's definitely not ideal. The ISR lambda function still gets invoked, but it gives the behavior I needed from dynamicParams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /