I'm using
custom-serverexample with localAPI as a base, whenever I try to build i get an APIError and build fails
Error:
Generating static pages (1/8) [== ]
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at eu (D:\site\.next\server\chunks\822.js:1:23042)
at stringify (<anonymous>)
at AsyncLocalStorage.run (node:async_hooks:346:14)
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at K (D:\site\.next\server\chunks\822.js:1:20048)
at stringify (<anonymous>)
at AsyncLocalStorage.run (node:async_hooks:346:14)
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at d (D:\site\.next\server\app\(site)\page.js:1:2858)
at stringify (<anonymous>)
⨯ APIError: The collection with slug blogs can't be found. Find Operation.
at P (D:\site\.next\server\app\(site)\page.js:6:712)
at stringify (<anonymous>)
⨯ APIError: The collection with slug members can't be found. Find Operation.
at _ (D:\site\.next\server\app\(site)\page.js:6:3161)
at stringify (<anonymous>)
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at eu (D:\site\.next\server\chunks\822.js:1:23042)
at stringify (<anonymous>)
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at K (D:\site\.next\server\chunks\822.js:1:20048)
at stringify (<anonymous>)
⨯ TypeError: Cannot read properties of null (reading 'useContext')
at b (D:\site\.next\server\chunks\756.js:1:24202)
at c (D:\site\.next\server\chunks\756.js:1:15638)
⨯ TypeError: Cannot read properties of undefined (reading 'localization')
at d (D:\site\.next\server\app\(site)\page.js:1:2858)
at stringify (<anonymous>)here's
package.jsonDoes anyone have a solution?
I can see some of the errors may be coming from your payload.config file (invalid collection slug names, etc)
Do you mind posting your configuration file?
I fixed the error of payload slugs. I was importing payload directly instead of using
getPayloadClientnow I get some other errors probably related to nextjs
// import { webpackBundler } from '@payloadcms/bundler-webpack'
import { viteBundler } from '@payloadcms/bundler-vite'
import { postgresAdapter } from '@payloadcms/db-postgres'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import dotenv from 'dotenv'
import path from 'path'
import { buildConfig } from 'payload/config'
import Assets from './collections/Assets'
import Blogs from './collections/Blogs'
import Comments from './collections/Comments'
import Members from './collections/Members'
import Tweets from './collections/Tweets'
import Users from './collections/Users'
import { Footer } from './globals/Footer'
import { Header } from './globals/Header'
import { Hero } from './globals/Hero'
import { requestLogger } from './middlewares/request-logger'
dotenv.config({
path: path.resolve(__dirname, '../../.env'),
})
export default buildConfig({
serverURL: process.env.NEXT_PUBLIC_SERVER_URL || '',
collections: [Blogs, Users, Assets, Members, Tweets, Comments],
globals: [Header, Hero, Footer],
routes: {
admin: '/admin',
},
admin: {
// inactivityRoute: '/shame',
user: Users.slug,
bundler: viteBundler(),
meta: {
titleSuffix: '- Shame Games',
favicon: '/favicon.ico',
},
},
rateLimit: {
max: 2000,
},
express: {
postMiddleware: [requestLogger],
},
editor: lexicalEditor({}),
cors: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
csrf: [process.env.NEXT_PUBLIC_SERVER_URL || ''].filter(Boolean),
db: postgresAdapter({
pool: {
connectionString: process.env.DATABASE_URI,
},
}),
typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'),
},
plugins: [
// redirects({
// collections: ['blogs'],
// overrides: {
// access: {
// read: admins,
// },
// },
// }),
],
})I'm trying to do suggested fix
https://nextjs.org/docs/messages/prerender-errorbut no results
hmmm
Do you know where that useContext error is coming from?
It's hard to tell from your current debug since it's chunked
I think it's from one of the radix components or next themes
I changed the bundler in payload config to from vite to webpack and the error is gone
I thought vite will only be used for building payload and not the nextjs 🤷♂️
Just in case anyone else has this issue with v2, I had NODE_ENV=development in my .env file. Even though the build script is setting this variable to production for builds, it caused this same issue while using Webpack
Star
Discord
online
Get dedicated engineering support directly from the Payload team.