Skip to content

TypeError when @payload-config path alias is missing from tsconfig.json #9796

@marwinhormiz

Description

@marwinhormiz

Describe the Bug

When the @payload-config path alias is missing from tsconfig.json's compilerOptions.paths, the package fails with a cryptic error:

node:path:1464
validateString(path, 'path');
^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at Object.extname (node:path:1464:5)
at findConfig (/home/marwinhormiz/Documents/bygglov/node_modules/.pnpm/payload@3.4.0_graphql@16.9.0_monaco-editor@0.52.0_react-dom@19.0.0-rc-66855b96-20241106_react_re2uwt7p7ymmoimatcnocwcioe/node_modules/payload/src/config/find.ts:70:12)
at bin (/home/marwinhormiz/Documents/bygglov/node_modules/.pnpm/payload@3.4.0_graphql@16.9.0_monaco-editor@0.52.0_react-dom@19.0.0-rc-66855b96-20241106_react_re2uwt7p7ymmoimatcnocwcioe/node_modules/payload/dist/bin/index.js:46:24)
at start (file:///home/marwinhormiz/Documents/bygglov/node_modules/.pnpm/payload@3.4.0_graphql@16.9.0_monaco-editor@0.52.0_react-dom@19.0.0-rc-66855b96-20241106_react_re2uwt7p7ymmoimatcnocwcioe/node_modules/payload/bin.js:30:13) {
code: 'ERR_INVALID_ARG_TYPE'
}

This happens because the code in getTSConfigPaths() silently returns undefined for configPath when the path alias is missing, which later causes a path resolution error.

Link to file

Current Behavior

  • If @payload-config path alias is missing, configPath becomes undefined
  • This undefined is passed to path operations causing a TypeError
  • The error message doesn't indicate the root cause (missing path alias)

Expected Behavior

Either:

  1. Throw a clear error message indicating that @payload-config path alias is required in tsconfig.json
  2. OR fall back to a default configuration path (e.g., './src/payload.config.ts')
  3. OR allow configuration via environment variables as an alternative

Link to the code that reproduces this issue

https://github.com/marwinhormiz/config-path-error

Reproduction Steps

  1. Remove @payload-config path alias from tsconfig.json:
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
      // @payload-config path alias removed
    }
  }
}
  1. Run any payload command such as generate:types or generate:importmap

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Node.js v20.18.1

Binaries:
  Node: 20.18.1
  npm: 10.8.2
  pnpm: 9.14.4
Relevant Packages:
  payload: 3.4.0
Operating System:
  Platform: linux
  Arch: x64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions