"cors" does not match any of the allowed types when build

default discord avatar
8 months ago
1 1

I get this error on yarn build. I set cors with cors: [process.env.FE_URL], it cause error, why?
But if I set cors: "*" run build ok

$ cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build
[16:40:13] ERROR (payload): There were 1 errors validating your Payload config
[16:40:13] ERROR (payload): 1: "cors" does not match any of the allowed types

Here is my config

export default buildConfig({
  serverURL: process.env.SERVER_URL,
  admin: {
    user: Users.slug,
  cors: [process.env.FE_URL],
  collections: [
  typescript: {
    outputFile: path.resolve(__dirname, "payload-types.ts"),
  graphQL: {
    schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
  plugins: [
  • discord user avatar
    Payload Team
    8 months ago

    What you have looks appears to be correct. Can you verify that you have a FE_URL defined in your .env?

    It must be a string insde the array or you'll get that error so my guess is that it isn't coming through.

    2 replies
  • discord user avatar
    Payload Team
    8 months ago

    Also maybe double-check that dotenv is being run in your config itself.

    Often times people only call dotenv in their server.ts file, which is not used during the build process, and that means your variable won't be defined when you go to call payload build. No harm in calling dotenv in both places!

  • default discord avatar
    8 months ago

    Thank you for replie me.
    I fixed that by add require("dotenv").config?.(); to file payload.config.ts

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.