diff --git a/src/config/find.ts b/src/config/find.ts index 08e2254695..7369ca6187 100644 --- a/src/config/find.ts +++ b/src/config/find.ts @@ -20,13 +20,24 @@ const findConfig = (): string => { return defaultPath; } - // Check for config in current working directory - const cwdPath = path.resolve(process.cwd(), 'payload.config.js'); - if (fs.existsSync(cwdPath)) { - return cwdPath; + const defaultTSPath = path.resolve(__dirname, '../../../payload.config.ts'); + + if (fs.existsSync(defaultTSPath)) { + return defaultTSPath; } - throw new Error('Error: cannot find Payload config. Please create a configuration file located at the root of your current working directory called "payload.config.js".'); + // Check for config in current working directory + const cwdJSPath = path.resolve(process.cwd(), 'payload.config.js'); + if (fs.existsSync(cwdJSPath)) { + return cwdJSPath; + } + + const cwdTSPath = path.resolve(process.cwd(), 'payload.config.ts'); + if (fs.existsSync(cwdTSPath)) { + return cwdTSPath; + } + + throw new Error('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".'); }; export default findConfig; diff --git a/src/config/load.ts b/src/config/load.ts index 36cedb8c6c..70f6d98196 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -7,12 +7,15 @@ import findConfig from './find'; const configPath = findConfig(); const loadConfig = (): Config => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const publicConfig = require(configPath); + let publicConfig = require(configPath); + + if (publicConfig.default) publicConfig = publicConfig.default; + return { ...publicConfig, paths: { - configDir: path.dirname(configPath), ...(publicConfig.paths || {}), + configDir: path.dirname(configPath), config: configPath, }, };