payloadcms / payload

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.
https://payloadcms.com
MIT License
23.12k stars 1.44k forks source link

Passing `config` option to `payload.init` still requires a `payload.config.js` file #5282

Open vixalien opened 6 months ago

vixalien commented 6 months ago

Link to reproduction

No response

Describe the Bug

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.

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

ha-sante commented 5 months ago

I have this error as well. @vixalien - Were you able to find a fix?

vixalien commented 5 months ago

No, but I'll be working on a PR soonish.

JBOClara commented 2 months ago

Any news or workaround ?