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: [
Users,
Pages,
Media,
Contacts,
],
typescript: {
outputFile: path.resolve(__dirname, "payload-types.ts"),
},
graphQL: {
schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
},
plugins: [
],
});
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.
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!
Thank you for replie me.
I fixed that by add require("dotenv").config?.();
to file payload.config.ts
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.