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.

Fixing CSS not defined Error in Next.js Production

default discord avatar
zed0547last year
64
@597024527070920704

@1136445496345501768

@782380557983940618

Can you share your page.tsx in the (payload) folder



This is only happening in production?



Also Payload versions

  • default discord avatar
    grey.shadowlast year

    only in production



    payload version "^3.2.1"



    src/app/(payload)/admin/[[...segments]]/page.tsx
    /* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
    /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
    import type { Metadata } from 'next'
    
    import config from '@payload-config'
    import { RootPage, generatePageMetadata } from '@payloadcms/next/views'
    import { importMap } from '../importMap'
    
    type Args = {
      params: Promise<{
        segments: string[]
      }>
      searchParams: Promise<{
        [key: string]: string | string[]
      }>
    }
    
    export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
      generatePageMetadata({ config, params, searchParams })
    
    const Page = ({ params, searchParams }: Args) =>
      RootPage({ config, params, searchParams, importMap })
    
    export default Page


    my react version is

    19.0.0-rc-65a56d0e-20241020

    , I updated like 4 seconds ago to the latest:

    19.0.0-rc-7670501b-20241124

    . gonna have to wait for the ci/cd to finish to see if that fixes it



    @654031862146007055

    is there anything else you need?

  • default discord avatar
    zed0547last year

    I doubt bumping react will fix it but lmk, I'm looking into it



    Thanks for the quick reply



    If that doesn't work, weird as it may sound, can you trying changing custom.scss to custom.css



    In (payload) and giving that a shot?

  • default discord avatar
    grey.shadowlast year

    it seems custom.scss is completely empty?



    @654031862146007055
  • default discord avatar
    zed0547last year

    Yeah, it's for custom styles

  • default discord avatar
    grey.shadowlast year

    would it be okay to just straight up delete it?

  • default discord avatar
    zed0547last year

    But it's weirding me out because it used to be just custom.css



    You can try but I'm pretty sure it'll just regenerate

  • default discord avatar
    grey.shadowlast year

    upgrading to the latest react version does not solve it



    I'll modify it to .css



    I am not even sure how its able to compile scss at all...

  • default discord avatar
    zed0547last year

    Oh wait check layout.tsx

  • default discord avatar
    grey.shadowlast year

    there is no scss in the package.json



    /* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
    /* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
    import config from '@payload-config'
    import '@payloadcms/next/css'
    import type { ServerFunctionClient } from 'payload'
    import { handleServerFunctions, RootLayout } from '@payloadcms/next/layouts'
    import React from 'react'
    
    import { importMap } from './admin/importMap.js'
    import './custom.scss'
    
    type Args = {
      children: React.ReactNode
    }
    
    const serverFunction: ServerFunctionClient = async function (args) {
      'use server'
      return handleServerFunctions({
        ...args,
        config,
        importMap,
      })
    }
    
    const Layout = ({ children }: Args) => (
      <RootLayout config={config} importMap={importMap} serverFunction={serverFunction}>
        {children}
      </RootLayout>
    )
    
    export default Layout


    its completely stock

  • default discord avatar
    zed0547last year

    Ok, after you change to .css adjust the reference in there too



    Hmm also

    @payloadcms/next/css

    si suspicious but those are the admin ui styles

  • default discord avatar
    grey.shadowlast year

    the weird thing is that the

    sass

    dependency is not even installed in this project

    @654031862146007055
  • default discord avatar
    zed0547last year

    Yeah, I hear ya but it's installed in admin, but obviously it has to be processed so I'm not sure why the custom is a scss



    it used to be just custom.css

  • default discord avatar
    grey.shadowlast year
    ~/app $ yarn info sass
    Usage Error: No package matched your request
    
    $ yarn info [-A,--all] [-R,--recursive] [-X,--extra #0] [--cache] [--dependents] [--manifest] [--name-only] [--virtuals] [--json] ...

    you sure?

  • default discord avatar
    zed0547last year

    Am I sure what?



    That scss is used in the Admin ui styles? Yes

  • default discord avatar
    grey.shadowlast year

    that I don't need to include sass

  • default discord avatar
    zed0547last year

    Shouldn't need to include sass



    To run it

  • default discord avatar
    grey.shadowlast year

    alright



    well... deploy pipeline is running. I'll let you know in a minute



    same error

  • default discord avatar
    zed0547last year

    You changed .scss and the reference in layout yeah?

  • default discord avatar
    grey.shadowlast year

    yes both

  • default discord avatar
    zed0547last year

    I'm confused why it's custom.scss now since by the time the admin ships to you the sass gets bundled as css and included in /dist/styles.css and exported as /next/css already, so I don't think it's

    @payloadcms/next/css
  • default discord avatar
    antefhpxlast year

    curious too see whether this error happens when building a default template



    or is it something specific to our configs

  • default discord avatar
    zed0547last year

    That's a good question



    Are you guys importing custom css into custom components anywhere in configs?



    Can you double check

  • default discord avatar
    grey.shadowlast year

    I do have a few custom components, but no custom css

  • default discord avatar
    antefhpxlast year

    i have some components with


    import 'react-toastify/dist/ReactToastify.css';

  • default discord avatar
    grey.shadowlast year

    including sass as dev dependency does indeed not fix it

  • default discord avatar
    zed0547last year

    Why not just use the sonner tooltip that comes out of the box?

  • default discord avatar
    grey.shadowlast year

    I'll try removing it from the layout

  • default discord avatar
    zed0547last year

    Your admin styles will go goofy but yeah

  • default discord avatar
    grey.shadowlast year

    I have git, so if it gets regenerated I'll be able to see it and just remove it again

  • default discord avatar
    antefhpxlast year

    thats a good point, i havent got to cleaning up my older components but will switch to sonner

  • default discord avatar
    zed0547last year

    Somehow I wonder if excluding the css import for admin styles will fix it

  • default discord avatar
    grey.shadowlast year

    funnily enough, removing the scss and editing the layout does not fix it

  • default discord avatar
    zed0547last year

    Greyshadow about to drop a bomb

  • default discord avatar
    grey.shadowlast year

    I am guessing when building, they are regenerated?

  • default discord avatar
    zed0547last year

    Can you try removing the

    @payloadcms/next/css

    from layout



    Oh, you

    did

    remove it?

  • default discord avatar
    grey.shadowlast year

    huh, but both are used?



    I removed the scss import from the layout



    didnt work

  • default discord avatar
    zed0547last year

    No no, I mean

    import '@payloadcms/next/css'
  • default discord avatar
    grey.shadowlast year

    I can try



    I think that its gonna break the entire admin ui

  • default discord avatar
    zed0547last year

    Yeah, they

    are

    the styling of the ui



    But I think somethings not being resolved correctly



    Honestly not too sure

  • default discord avatar
    grey.shadowlast year

    well... the style certainly is missing in my dev build so far



    doomed to wait 5 minutes for my pipeline every time

  • default discord avatar
    zed0547last year
    /next/dist/prod/styles.css

    are the style sfor the whole admin ui, in the package.json (near the bottom) it gets mapped to

    /next/css

    So that's what

    /next/css

    import is

  • default discord avatar
    grey.shadowlast year

    guess we doing over time

  • default discord avatar
    zed0547last year

    Hmm I'm not getting this issue on a local build of the templates

  • default discord avatar
    grey.shadowlast year
    FROM node:20.11.0-alpine AS base
    
    WORKDIR /home/node/app
    
    RUN mkdir -p /home/node/app/media \
        && chown node /home/node/app/media
    
    RUN corepack enable && corepack prepare yarn@4 --activate
    
    RUN apk add --update git
    FROM base AS production
    
    COPY package.json yarn.lock .yarnrc.yml ./
    RUN yarn install
    COPY . .
    
    ENV NODE_ENV=production
    
    RUN mkdir .next && chown node:node .next
    
    USER node
    
    RUN yarn build
    
    CMD ["yarn", "start"]


    this is how I build for production



    doesn't work



    everything just looks broken now

  • default discord avatar
    zed0547last year

    Lol yeah

  • default discord avatar
    grey.shadowlast year

    exact same error

  • default discord avatar
    zed0547last year

    Damn



    Nothing stands out to me in your dockerfile



    @597024527070920704

    Also docker?

  • default discord avatar
    grey.shadowlast year

    im leaving the office for today, maybe tomorrow I can further investigate

  • default discord avatar
    zed0547last year

    Sounds good, I'll keep looking into it and will come back here if I find anything useful

  • default discord avatar
    antefhpxlast year

    nope, no docker here



    will also report back if i find something

  • default discord avatar
    zed0547last year
  • discord user avatar
    alessiogr
    last year

    Will have a canary ready in the next 5m, then you don't need to wait for the next release ^^

  • default discord avatar
    zed0547last year

    Absolutely sensational



    Thanks Alessio

  • discord user avatar
    alessiogr
    last year

    you're welcome! Here's the canary with the fix:

    3.2.2-canary.a11698b
  • default discord avatar
    zed0547last year
    @782380557983940618

    @1136445496345501768

    @597024527070920704
  • default discord avatar
    grey.shadowlast year

    Ah classic



    Thanks for the fix Alessio



    Oh funny, I don't have permission to make it as solved :p

  • default discord avatar
    zed0547last year

    Maybe because I moved it?

  • default discord avatar
    grey.shadowlast year

    Likely

  • discord user avatar
    alessiogr
    last year

    oh strange, the bot should be able to detect the thread creator for moved threads

  • default discord avatar
    antefhpxlast year

    Thanks

    @360823574644129795
  • default discord avatar
    grey.shadowlast year

    I just did a deployed a release this morning with the canary version, and it has indeed been fixed



    Thanks again

  • default discord avatar
    zed0547last year

    You guys should be able to move off canary and on to 3.2.2 now that it's released

  • default discord avatar
    antefhpxlast year

    👏🏼 good stuff

  • default discord avatar
    grey.shadowlast year

    guess we doing overtime again 💀

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.