microsoft / microsoft/aspire

TypeScript starter API templates fail tsc due to .ts import extension

Open
#17,224 1 comment 0 reactions 0 assignees View on GitHub
area-templates triage:bot-seen
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

## Problem

The TypeScript starter API templates import `instrumentation.ts` with an explicit `.ts` extension, but the template API `tsconfig.json` does not enable `allowImportingTsExtensions`. A plain TypeScript compile therefore fails with `TS5097`.

The generated app can still run through the current `npm start` path because it uses `tsx`, but the template source does not type-check with `tsc` as written.

cc @IEvangelist

## Repro

From the repo root:

```bash
cd src/Aspire.Cli/Templating/Templates/ts-starter/api
npm install
npm exec --yes --package typescript -- tsc -p tsconfig.json --noEmit
```

Expected: the template API TypeScript source type-checks successfully.

Actual:

```text
src/index.ts:6:8 - error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

6 import "./instrumentation.ts";
~~~~~~~~~~~~~~~~~~~~~~
```

The same repro applies to:

```bash
cd src/Aspire.Cli/Templating/Templates/java-starter/api
npm install
npm exec --yes --package typescript -- tsc -p tsconfig.json --noEmit
```

and to the playground app:

```bash
cd playground/JavaAppHost/api
npm install
npm exec --yes --package typescript -- tsc -p tsconfig.json --noEmit
```

## Source files with the problematic import

Each file imports `./instrumentation.ts` from `src/index.ts`:

- `src/Aspire.Cli/Templating/Templates/ts-starter/api/src/index.ts`
- `src/Aspire.Cli/Templating/Templates/java-starter/api/src/index.ts`
- `playground/JavaAppHost/api/src/index.ts`

## Notes

The import currently looks like this:

```ts
import "./instrumentation.ts";
```

A likely fix is to make the import and TypeScript configuration agree, for example by removing the `.ts` extension from the import or by explicitly enabling compatible TypeScript compiler settings if keeping extensionful TypeScript imports is intentional.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.