Skip to content

loader: friendlier error when importing .ts without a TS loader #15

Description

@Cryptoteep

Bug

loadPromptsFromDir dynamically import()s .ts files. In plain Node (no tsx/ts-node/bun), this throws a fairly cryptic ERR_UNKNOWN_FILE_EXTENSION. The LoaderError we wrap it in says "Failed to import" but doesn't tell the user why or how to fix it.

Expected

When the underlying error is ERR_UNKNOWN_FILE_EXTENSION for a .ts file, the thrown LoaderError message should include a hint:

Failed to import <file>: Node can't import .ts files directly. Run with tsx, bun, or ts-node, or pre-compile to .js.

Implementation

In src/loader.ts loadPromptFile, inspect the caught error's code (Node errors set .code). If it's ERR_UNKNOWN_FILE_EXTENSION, augment the message.

Acceptance

  • Detection + helpful message.
  • Unit test using a fixture .ts file under a plain node run (or simulate by stubbing).
  • docs/getting-started.md note about TS loaders.

/label "good first issue" "area:loader" "bug"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:loaderFilesystem loader and prompt discoverybugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions