Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
When you provide the config option to payload.init like so, it doesn't work because payload still expects a config file (payload.config.js) even though you already provided it as the config option.
To Reproduce
Create a simple repo that initializes payload using the following pattern.
payload.init({
config: // ... your imported config,
});
This will fail with the following message:
Error: cannot find Payload config. Please create a configuration file located at the root of your current working directory called "payload.config.js" or "payload.config.ts".
The error is there even though you provided the config as an option. Payload should not error out when no config file is found while I passed in the config option.
You can see payload is still searching for the config file, even though we already provided configuration options in the options. In my opinion, the code should be wrapped around a try/catch block to prevent this.
Link to reproduction
No response
Describe the Bug
When you provide the
config
option topayload.init
like so, it doesn't work because payload still expects a config file (payload.config.js
) even though you already provided it as theconfig
option.To Reproduce
Create a simple repo that initializes payload using the following pattern.
This will fail with the following message:
The error is there even though you provided the config as an option. Payload should not error out when no config file is found while I passed in the config option.
I've traced the buggy code to here:
https://github.com/payloadcms/payload/blob/0780ff22bb5064abadd20414ad8b491ec6388e20/packages/payload/src/payload.ts#L325-L336
You can see payload is still searching for the config file, even though we already provided configuration options in the options. In my opinion, the code should be wrapped around a
try/catch
block to prevent this.Payload Version
2.11.2
Adapters and Plugins
No response