Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

TypeError: Cannot read properties of undefined (reading 'toLowerCase')

default discord avatar
grizshark5738last year
9

I have been trying for two days to get a successful build deployed in Payload Cloud. I have encountered this error and cannot find a way around it:



TypeError: Cannot read properties of undefined (reading 'toLowerCase')



This is occurring when I try to access the Payload Admin (both in development and in production) at /admin



I have searched my entire project looking for anything related to "toLowerCase" with no luck. I am stuck and not sure what to do -- currently everything is working as intended, but I cannot view my /admin in dev or production.



I have tried changing my Payload version to a lower version (saw a comment that suggested it) but no luck:



"dependencies": {


"@headlessui/react": "^2.1.2",


"@heroicons/react": "^2.1.5",


"@lexical/react": "^0.16.1",


"@lexical/rich-text": "^0.16.1",


"@payloadcms/bundler-webpack": "^1.0.3",


"@payloadcms/db-mongodb": "^1.0.3",


"@payloadcms/richtext-lexical": "^0.11.3",


"@rewind-ui/core": "^0.19.11",


"@tailwindcss/typography": "^0.5.13",


"axios": "^1.7.2",


"cors": "^2.8.5",


"date-fns": "^3.6.0",


"dotenv": "^16.4.5",


"embla-carousel-autoplay": "^8.1.7",


"embla-carousel-react": "^8.1.7",


"express": "^4.19.2",


"framer-motion": "^11.3.0",


"googleapis": "^140.0.1",


"ical": "^0.8.0",


"ical.js": "^2.0.1",


"mongoose": "^8.2.2",


"next": "14.2.13",


"payload": "2.20.0",


"react": "^18.2.0",


"react-dom": "^18.2.0"


},



"devDependencies": {


"@swc/core": "^1.3.100",


"@swc/helpers": "^0.5.3",


"@types/express": "^4.17.21",


"@types/node": "^20.4.2",


"@types/react": "^18.2.0",


"@types/react-dom": "^18.2.0",


"autoprefixer": "^10.4.19",


"axe-core": "^4.8.4",


"cross-env": "^7.0.3",


"eslint": "^8.44.0",


"eslint-config-next": "14.2.13",


"eslint-plugin-jsx-a11y": "^6.8.0",


"eslint-plugin-react": "^7.34.1",


"eslint-plugin-react-hooks": "^4.6.0",


"nodemon": "^3.0.1",


"postcss": "^8.4.40",


"tailwindcss": "^3.4.6"


}

  • discord user avatar
    denolfe
    last year

    Does this happen locally as well? Can you provide the full error stack trace?

  • default discord avatar
    grizshark5738last year

    main.js:194472 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'toLowerCase')


    at main.js:194472:24


    at formatLabels (main.js:127083:36)


    at sanitizeCollection (main.js:121621:75)


    at main.js:121898:85


    at Array.map (<anonymous>)


    at sanitizeConfig (main.js:121898:45)


    at buildConfig (main.js:121718:41)


    at ./src/payload.config.js (main.js:277466:14)


    at

    webpack_require

    (main.js:285313:33)


    at fn (main.js:285524:21)



    And yes, this occurs locally -- in production I just get a 404 trying to access /admin.



    Updated to v2.8.2 to see if that made a difference, same issue (with some new errors), trying to load localhost:3000/admin



    main.204021681a32b938d2ab.js:100 TypeError: Cannot read properties of null (reading 'useReducer')


    at t.useReducer (main.204021681a32b938d2ab.js:146:6055)


    at E (main.204021681a32b938d2ab.js:138:128066)


    at z (main.204021681a32b938d2ab.js:138:139878)


    at oy (main.204021681a32b938d2ab.js💯60923)


    at s (main.204021681a32b938d2ab.js💯119440)


    at lI (main.204021681a32b938d2ab.js💯99099)


    at main.204021681a32b938d2ab.js💯98966


    at lR (main.204021681a32b938d2ab.js💯98973)


    at lS (main.204021681a32b938d2ab.js💯95725)


    at lE (main.204021681a32b938d2ab.js💯94280)


    o9 @ main.204021681a32b938d2ab.js:100Understand this error


    main.204021681a32b938d2ab.js:100 Uncaught TypeError: Cannot read properties of null (reading 'useReducer')


    at t.useReducer (main.204021681a32b938d2ab.js:146:6055)


    at E (main.204021681a32b938d2ab.js:138:128066)


    at z (main.204021681a32b938d2ab.js:138:139878)


    at oy (main.204021681a32b938d2ab.js💯60923)


    at s (main.204021681a32b938d2ab.js💯119440)


    at lI (main.204021681a32b938d2ab.js💯99099)


    at main.204021681a32b938d2ab.js💯98966


    at lR (main.204021681a32b938d2ab.js💯98973)


    at lS (main.204021681a32b938d2ab.js💯95725)


    at lE (main.204021681a32b938d2ab.js💯94280)Understand this error


    main.204021681a32b938d2ab.js:108 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'toLowerCase')


    at main.204021681a32b938d2ab.js:108:21289


    at l (main.204021681a32b938d2ab.js:92:286238)


    at w (main.204021681a32b938d2ab.js:92:224692)


    at main.204021681a32b938d2ab.js:92:228817


    at Array.map (<anonymous>)


    at h (main.204021681a32b938d2ab.js:92:228797)


    at a (main.204021681a32b938d2ab.js:92:226179)


    at 49832 (main.204021681a32b938d2ab.js:154:9866)


    at n (main.204021681a32b938d2ab.js:158:513405)


    at 61044 (main.204021681a32b938d2ab.js:69:29247)



    Please, if anyone has a solution it would be very helpful -- stumbled on another thread with the 'useReducer' error, they managed to update mongodb and it worked. I tried to do the same, no luck.



    Still cannot render Payload Admin locally or in production. Otherwise no build errors -- seems to be client side issue.

  • discord user avatar
    denolfe
    last year

    Provide your config

  • default discord avatar
    grizshark5738last year


    So, the strange thing is, locally and in production, I can see all of the collection data (navigation/news articles/teams) but I cannot render the Payload Admin (/admin) in either instance. I am at a loss here...



    Still struggling with this, I have tried to revisit my package.json and server settings with no luck. Still cannot access the /admin locally or in production.



    Payload initialized successfully


    Preparing Next.js app...


    [06:16:48] INFO (payload): Connected to MongoDB server successfully!


    [06:16:48] INFO (payload): Starting Payload...


    Next.js app prepared


    Express server listening on port 3000


    webpack built 9456ce5c345cd6b89f61 in 7581ms


    webpack compiled successfully


    <w> [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: No serializer registered for ConcatSource


    <w> while serializing webpack/lib/util/registerExternalSerializer.webpack-sources/ConcatSource -> Array { 2 items } -> ConcatSource


    2024-09-25T10:16:58.975Z - GET /admin/

    webpack_hmr
    2024-09-25T10:16:59.035Z - GET /admin/

    webpack_hmr


    2024-09-25T10:17:08.350Z - GET /admin/collections/players


    2024-09-25T10:17:08.390Z - GET /admin/main.js


    2024-09-25T10:17:08.684Z - GET /admin/

    webpack_hmr
    2024-09-25T10:17:11.774Z - GET /admin
    2024-09-25T10:17:11.830Z - GET /admin/main.js
    2024-09-25T10:17:11.959Z - GET /admin/

    webpack_hmr


    webpack building...


    webpack built e9760ac7a69e3bc0092d in 1924ms


    webpack compiled successfully


    2024-09-25T10:27:04.381Z - GET /admin/main.9456ce5c345cd6b89f61.hot-update.json


    2024-09-25T10:27:04.392Z - GET /admin/main.9456ce5c345cd6b89f61.hot-update.js



    I did encounter an issue where we are constantly fetching this while trying to npm run dev:

  • discord user avatar
    denolfe
    last year

    My guess is that there's something incorrect about your config, but it's not telling you because it is in JS.



    I'd try swapping it to TS to get type checking



    Could start commenting out collections and run after each to narrow down the problem

  • default discord avatar
    grizshark5738last year

    I’ll give that a try, it was a battle to get everything working which is why I have a mix of CommonJS as well.



    I’ll try the commenting out approach first

  • discord user avatar
    denolfe
    last year

    Maybe try an empty arrow for collections first



    Array*



    And see if it has to do with that at all

  • default discord avatar
    grizshark5738last year

    Updated config to use the bare minimum and now I can access /admin...



    Unfortunately that leaves me with a ton of work to figure out why, hah



    Well that was easier than I thought, after two and half days, the solution was to just define all of my collections in my config without trying to import them. Everything seems to be working now -- locally and in production. Thanks

    @967118574445547650

    for the troubleshooting tip!

  • discord user avatar
    denolfe
    last year

    Awesome 🙌

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.