Skip to content

Wayfinder generates invalid TS when namespace repeats (e.g. Prism/Prism), causing duplicate identifier in barrel index.ts #126

@cieplik206

Description

@cieplik206

Wayfinder Version

0.1.12

Laravel Version

12.x

PHP Version

8.4.11

Description

When a controller namespace segment repeats (e.g. App\Http\Controllers\Prism\Prism\Http\Controllers...), the generated barrel file resources/js/actions/Prism/index.ts contains an import and a const with the same
identifier:

  import Prism from './Prism'

  const Prism = {
      Prism: Object.assign(Prism, Prism),
  }

  export default Prism

This causes TypeScript errors:

  • TS2440: Import declaration conflicts with local declaration of 'Prism'
  • TS7022: 'Prism' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
  • TS2448: Block-scoped variable 'Prism' used before its declaration.

Steps To Reproduce

  1. Create controllers under a repeated namespace path, e.g. App\Http\Controllers\Prism\Prism\Http\Controllers\PrismChatController.

  2. Ensure routes point to those controllers.

  3. Run:

    php artisan wayfinder:generate --path=resources/js --with-form

  4. Open resources/js/actions/Prism/index.ts.

Expected Behavior
Generated barrel file should use distinct identifiers (or safe aliases) so that import and const names don’t collide.

Actual Behavior
Generated index.ts contains import Prism and const Prism = { ... }, causing TS errors and breaking pnpm run types.

Additional Context / Suggestion
The issue seems to come from barrel generation using the same safeMethod name for both import alias and the exported const. A simple fix could be to disambiguate the top-level export variable name when it matches a child
import (e.g. PrismNamespace or PrismRoot), or apply TypeScript::safeMethod differently for the exported const.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions