⨯ ReferenceError: CSS is not defined
at <unknown> (/home/node/app/.next/server/app/(payload)/admin/[[...segments]]/page.js:43:52079)
at Object.nr [as useMemo] (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:36398)
at t.useMemo (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:68:6660)
at r6 (/home/node/app/.next/server/app/(payload)/admin/[[...segments]]/page.js:43:52060)
at r5 (/home/node/app/.next/server/app/(payload)/admin/[[...segments]]/page.js:43:53220)
at n$ (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:45906)
at nI (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:47681)
at nL (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:65480)
at nN (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:63111)
at nB (/home/node/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:20:68893) {
digest: '1420037132'
}
```I get this error on `/admin` (or any initial page load on routes for the payload admin) in production
#Fixing CSS not defined Error in Next.js Production
117 messages · Page 1 of 1 (latest)
Original message from @tranquil echo - Moved from #core-dev message
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
@neon cosmos @astral flume
@tranquil echo Can you share your page.tsx in the (payload) folder
This is only happening in production?
Also Payload versions
only in production
payload version "^3.2.1"
src/app/(payload)/admin/[[...segments]]/page.tsx
/* 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
@barren fossil
is there anything else you need?
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?
Yeah, it's for custom styles
would it be okay to just straight up delete it?
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
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...
Oh wait check layout.tsx
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
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
the weird thing is that the sass dependency is not even installed in this project @barren fossil
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
~/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?
that I don't need to include sass
alright
well... deploy pipeline is running. I'll let you know in a minute
same error
You changed .scss and the reference in layout yeah?
yes both
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
curious too see whether this error happens when building a default template
or is it something specific to our configs
That's a good question
Are you guys importing custom css into custom components anywhere in configs?
Can you double check
I do have a few custom components, but no custom css
i have some components with
import 'react-toastify/dist/ReactToastify.css';
including sass as dev dependency does indeed not fix it
Why not just use the sonner tooltip that comes out of the box?
I'll try removing it from the layout
Your admin styles will go goofy but yeah
I have git, so if it gets regenerated I'll be able to see it and just remove it again
thats a good point, i havent got to cleaning up my older components but will switch to sonner
Somehow I wonder if excluding the css import for admin styles will fix it
funnily enough, removing the scss and editing the layout does not fix it
Greyshadow about to drop a bomb
I am guessing when building, they are regenerated?
No no, I mean import '@payloadcms/next/css'
Yeah, they are the styling of the ui
But I think somethings not being resolved correctly
Honestly not too sure
well... the style certainly is missing in my dev build so far
doomed to wait 5 minutes for my pipeline every time
/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
guess we doing over time
Hmm I'm not getting this issue on a local build of the templates
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
Lol yeah
exact same error
im leaving the office for today, maybe tomorrow I can further investigate
Sounds good, I'll keep looking into it and will come back here if I find anything useful
Will have a canary ready in the next 5m, then you don't need to wait for the next release ^^
you're welcome! Here's the canary with the fix: 3.2.2-canary.a11698b
@tranquil echo @astral flume @neon cosmos
You do not have permission to mark this thread as solved. Only thread creators, contributors and payload team members can mark a thread as solved.
Oh funny, I don't have permission to make it as solved :p
Maybe because I moved it?
Glad your issue was resolved! :tada: If you want to help make payload better, please give us a :star: on GitHub and review us - It helps us a lot.
🌟 Star Us on GitHub
👍 Review Us
Likely
oh strange, the bot should be able to detect the thread creator for moved threads
Thanks @ripe kestrel
I just did a deployed a release this morning with the canary version, and it has indeed been fixed
Thanks again
You guys should be able to move off canary and on to 3.2.2 now that it's released
👏🏼 good stuff