TypeError: Cannot read properties of undefined (reading 'Analytics') with NextJS 13.0.0
JamesDHW opened this issue · 0 comments
JamesDHW commented
Problem
When following the Quickstart instructions for Vercel Audiences, building my NextJS (13.0.0) project results in an error when running next build
:
> next build
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
info - Creating an optimized production build
info - Compiled successfully
info - Linting and checking validity of types
info - Collecting page data
[ ] info - Generating static pages (0/3)
TypeError: Cannot read properties of undefined (reading 'Analytics')
at Oa (.next/server/chunks/759.js:1025:56)
at Ia (.next/server/chunks/759.js:1138:50)
at Array.toJSON (.next/server/chunks/759.js:915:32)
at stringify (<anonymous>)
at S (./.next/server/chunks/759.js:1213:51)
at Object.start (.next/server/chunks/759.js:1324:53)
at setupReadableByteStreamController (node:internal/webstreams/readablestream:2665:23)
at setupReadableByteStreamControllerFromSource (node:internal/webstreams/readablestream:2702:3)
at new ReadableStream (node:internal/webstreams/readablestream:240:7)
at exports.renderToReadableStream (.next/server/chunks/759.js:1321:24)
[Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.] {
digest: '3412299338'
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'Analytics')
Minimum reproducible example
I can reproduce this by:
- Running
pnpm create next-app
- Setting the NextJS version to
13.0.0
in thepackage.json
a.pnpm install
again to install13.0.0
b. remove the exportedmetadata
constant fromlayout.tsx
which wasn't supported in NextJS13.0.0
c. remove theimport { Inter } from 'next/font/google'
frompage.tsx
- Follow the Quickstart Guide for NextJS 13 with the Analytics tag in the
/app
directory. - Run
pnpm run build
which should fail with the above error!
The fix
I updated my NextJS version to "next": "13.2.4",
!
I couldn't find any other issues relating to this or mention in the docs (<Analytics />
only working for given versions of NextJS) - hopefully posting the issue helps!