Skip to content

Commit dafaa96

Browse files
kentcdoddsjansepke
andauthored
remove tsconfig aliases (#1054)
* remove tsconfig aliases as typescript reuses package.json import config * update decision docs --------- Co-authored-by: Jan Sepke <[email protected]>
1 parent 5b62cb9 commit dafaa96

File tree

10 files changed

+56
-28
lines changed

10 files changed

+56
-28
lines changed

app/components/error-boundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
useParams,
77
useRouteError,
88
} from 'react-router'
9-
import { getErrorMessage } from '#app/utils/misc'
9+
import { getErrorMessage } from '#app/utils/misc.tsx'
1010

1111
type StatusHandler = (info: {
1212
error: ErrorResponse

app/routes/admin/cache/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useSearchParams,
99
useSubmit,
1010
} from 'react-router'
11-
import { GeneralErrorBoundary } from '#app/components/error-boundary'
11+
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
1212
import { Field } from '#app/components/forms.tsx'
1313
import { Spacer } from '#app/components/spacer.tsx'
1414
import { Button } from '#app/components/ui/button.tsx'

app/routes/admin/cache/sqlite.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { cache } from '#app/utils/cache.server.ts'
44
import {
55
getInstanceInfo,
66
getInternalInstanceDomain,
7-
} from '#app/utils/litefs.server'
7+
} from '#app/utils/litefs.server.ts'
88
import { type Route } from './+types/sqlite.ts'
99

1010
export async function updatePrimaryCacheValue({

app/utils/auth.server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { http, HttpResponse } from 'msw'
22
import { describe, expect, test } from 'vitest'
3-
import { server } from '#tests/mocks'
3+
import { server } from '#tests/mocks/index.ts'
44
import { consoleWarn } from '#tests/setup/setup-test-env.ts'
55
import { checkIsCommonPassword, getPasswordHashParts } from './auth.server.ts'
66

docs/decisions/031-imports.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Date: 2023-08-16
44

5-
Status: accepted
5+
Status: superseded by [046-remove-path-aliases](./046-remove-path-aliases.md)
6+
due to TypeScript's native support for the `"imports"` field in package.json.
67

78
## Context
89

@@ -27,21 +28,14 @@ and manually modify.
2728
Despite the magic of Path aliases, they are actually a standard `package.json`
2829
supported feature. Sort of.
2930
[The `"imports"` field](https://nodejs.org/api/packages.html#imports) in
30-
`package.json` allows you to configure aliases for your imports. It's not
31-
exactly the same as TypeScript Path aliases, and using them doesn't give you
32-
autocomplete with TypeScript
33-
([yet](https://github.com/microsoft/TypeScript/pull/55015)), but if you
34-
configure both, then you can get the best of both worlds!
31+
`package.json` allows you to configure aliases for your imports.
32+
TypeScript also uses this for its own Path aliases since version 5.4
33+
so you get autocomplete and type checking for your imports.
3534

3635
By using the `"imports"` field, you don't have to do any special configuration
3736
for `vitest` or `eslint` to be able to resolve imports. They just resolve them
3837
using the standard.
3938

40-
And by using the `tsconfig.json` `paths` field configured in the same way as the
41-
`"imports"` field, you get autocomplete and type checking for your imports. This
42-
should hopefully be temporary until TypeScript supports the `"imports"` field
43-
directly.
44-
4539
One interesting requirement for `imports` is that they _must_ start with the `#`
4640
character to disambiguate from other imports. This is a bit annoying, but it's
4741
something that's not difficult to get used to. They also _must not_ start with
@@ -50,19 +44,14 @@ again it's just a matter of familiarity. So it's no big deal.
5044

5145
## Decision
5246

53-
We're going to configure `"imports"` in the `package.json` and `paths` in the
54-
`tsconfig.json` to use path aliases for imports.
47+
We're going to configure `"imports"` in the `package.json` to use path aliases for imports.
5548

5649
We'll set it to `"#*": "./*"` which will allow us to import anything in the root
5750
of the repo with `#<dirname>/<filepath>`.
5851

5952
## Consequences
6053

6154
This is unfortunately _very_ soon after making the decision to drop the alias.
62-
But I see this as slightly different because we're only using the alias to make
63-
up for a shortcoming in TypeScript temporarily. Once TypeScript supports the
64-
`"imports"` field, we can drop the `paths` field and just use the `"imports"`
65-
standard for Node.js.
6655

6756
If someone wants to use the Epic Stack without Node.js, and their runtime
6857
doesn't support `package.json` imports (I'm not sure whether other runtimes do
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Remove Path Aliases
2+
3+
Date: 2025-10-23
4+
5+
Status: accepted
6+
7+
## Context
8+
9+
In [031-imports](./031-imports.md), we implemented path aliases using both the
10+
`"imports"` field in `package.json` and the `paths` field in `tsconfig.json`.
11+
This was done as a temporary solution because TypeScript didn't natively support
12+
the `"imports"` field, requiring us to maintain both configurations to get
13+
autocomplete and type checking.
14+
15+
However, TypeScript has now added native support for the `"imports"` field in
16+
`package.json` (as referenced in the original decision's "yet" link). This means
17+
we no longer need the `paths` configuration in `tsconfig.json` to get proper
18+
TypeScript support for our imports.
19+
20+
## Decision
21+
22+
We're removing the path aliases configuration from `tsconfig.json` and relying
23+
solely on the `"imports"` field in `package.json`. This simplifies our
24+
configuration and aligns with the standard Node.js approach.
25+
26+
The `"imports"` field will continue to work as before, providing the same import
27+
resolution functionality, but now with full TypeScript support without requiring
28+
duplicate configuration.
29+
30+
## Consequences
31+
32+
- **Simplified configuration**: We no longer need to maintain both
33+
`package.json` imports and `tsconfig.json` paths
34+
- **Standard compliance**: We're now using the standard Node.js approach without
35+
TypeScript-specific workarounds
36+
- **Reduced maintenance**: One less configuration to keep in sync
37+
- **Better tooling support**: TypeScript now natively understands the
38+
`"imports"` field, providing better IDE support
39+
40+
This supersedes [031-imports](./031-imports.md) as the current approach for
41+
handling imports in the Epic Stack.

prisma/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { faker } from '@faker-js/faker'
22
import { prisma } from '#app/utils/db.server.ts'
3-
import { MOCK_CODE_GITHUB } from '#app/utils/providers/constants'
3+
import { MOCK_CODE_GITHUB } from '#app/utils/providers/constants.ts'
44
import {
55
createPassword,
66
createUser,

tests/e2e/onboarding.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { prisma } from '#app/utils/db.server.ts'
44
import {
55
normalizeEmail,
66
normalizeUsername,
7-
} from '#app/utils/providers/provider'
7+
} from '#app/utils/providers/provider.ts'
88
import {
99
USERNAME_MAX_LENGTH,
1010
USERNAME_MIN_LENGTH,
11-
} from '#app/utils/user-validation'
11+
} from '#app/utils/user-validation.ts'
1212
import { readEmail } from '#tests/mocks/utils.ts'
1313
import {
1414
createUser,

tests/playwright-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
sessionKey,
99
} from '#app/utils/auth.server.ts'
1010
import { prisma } from '#app/utils/db.server.ts'
11-
import { MOCK_CODE_GITHUB_HEADER } from '#app/utils/providers/constants.js'
12-
import { normalizeEmail } from '#app/utils/providers/provider.js'
11+
import { MOCK_CODE_GITHUB_HEADER } from '#app/utils/providers/constants.ts'
12+
import { normalizeEmail } from '#app/utils/providers/provider.ts'
1313
import { authSessionStorage } from '#app/utils/session.server.ts'
1414
import { createUser } from './db-utils.ts'
1515
import {

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"types": ["@react-router/node", "vite/client"],
77
"rootDirs": [".", "./.react-router/types"],
88
"paths": {
9-
"#app/*": ["./app/*"],
10-
"#tests/*": ["./tests/*"],
119
"@/icon-name": [
1210
"./app/components/ui/icons/types.ts",
1311
"./types/icon-name.d.ts"

0 commit comments

Comments
 (0)