Skip to content

[StimulusBundle] Exception thrown when .ts controller transpiled to .js in the same directory #2701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
phasdev opened this issue Apr 28, 2025 · 2 comments · May be fixed by #2702
Open

[StimulusBundle] Exception thrown when .ts controller transpiled to .js in the same directory #2701

phasdev opened this issue Apr 28, 2025 · 2 comments · May be fixed by #2702
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed

Comments

@phasdev
Copy link

phasdev commented Apr 28, 2025

The loadCustomControllers function iterates over all .ts and .js files in the project's controllers path to build a controller map.

My project has a build step where TypeScript controllers are transpiled to JavaScript files that are saved alongside the source TypeScript files. My asset mapper config excludes TypeScript files since I'm only interested in serving JavaScript.

When loadCustomControllers iterates over all .ts and .js files in my controllers path, it tries to load mapped assets for my .ts controllers. But since these files are excluded, the returned asset is null and an exception is thrown when it tries to read the sourcePath property on the null asset.

Controller files should be a mapped asset. Not finding one indicates a problem so an exception should be thrown (e.g. see null mapped asset check in loadUxControllers function). However the loadCustomControllers function doesn't realize there are .js and .ts versions of the same controller and can skip processing the missing version.

I expected that I could exclude .ts controller files when .js versions are available.

Here's my proposed fix:

  • Skip mapping .ts controller file if a .js version is available
  • Add a null asset check and throw an exception similar to one thrown in loadUxControllers

Related: #1210

@phasdev phasdev added the Bug Bug Fix label Apr 28, 2025
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Apr 28, 2025
@phasdev phasdev changed the title [Stimulus Bundle] Exception thrown when .ts controller are transpiled to .js in the same directory [Stimulus Bundle] Exception thrown when .ts controller transpiled to .js in the same directory Apr 28, 2025
@phasdev phasdev changed the title [Stimulus Bundle] Exception thrown when .ts controller transpiled to .js in the same directory [StimulusBundle] Exception thrown when .ts controller transpiled to .js in the same directory Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants