trails/apps/journal/app/lib
Ullrich Schäfer 10deae88c9
fix: extensionless server-side imports + lint rule to catch them
## Symptom

Grafana's \`app-crash-log\` alert fires on every deploy. The Loki query
that backs it (\`ERR_|FATAL|uncaughtException|…\`) matches:

  Error [ERR_MODULE_NOT_FOUND]: Cannot find module
  '/app/apps/journal/app/lib/logger.server' imported from
  '/app/apps/journal/app/lib/email.server.ts'

A real bug, not a false positive: \`email.server.ts\` line 2 was
\`import { logger } from \"./logger.server\"\` — no extension.

## Why typecheck didn't catch it

\`tsconfig.base.json\` sets \`moduleResolution: \"bundler\"\`. The bundler
resolver accepts extensionless relative imports because Vite / esbuild
/ webpack resolve them at build time. TypeScript was happy.

Production runs \`node --experimental-strip-types server.ts\`, which
uses Node's NodeNext ESM resolver — strict about extensions. The two
resolvers disagree silently for files Node loads directly (server.ts,
\`.server.ts\` modules dynamically imported from it, and jobs).

## Fix

1. **Added \`.ts\` extensions to the 4 broken imports** I could find:
   - \`apps/journal/app/lib/email.server.ts\` → \`./logger.server.ts\`
     (the actual deploy-blocker)
   - \`apps/planner/app/lib/brouter.ts\` → \`./route-merge.ts\`, \`./http.server.ts\`
   - \`apps/planner/app/lib/use-nearby-pois.ts\` → \`./overpass.ts\`
   - \`packages/map/src/MapView.tsx\` → \`./layers.ts\` (caught by the rule)

2. **Added \`eslint-plugin-import-x\` with \`import-x/extensions: always\`**,
   scoped to files Node actually executes raw:
   - \`apps/*/server.ts\`
   - \`apps/*/app/lib/**/*.server.ts\`
   - \`apps/*/app/jobs/**/*.ts\`
   - \`packages/*/src/**/*.{ts,tsx}\`

   Ignored: route-scoped \`*.server.ts\` files (bundled by Vite into the
   React Router build, never loaded by Node), and test files (Vitest's
   own resolver).

## What's still possible

- Non-\`.server.ts\` files in \`app/lib\` (e.g. \`legal.ts\`, \`actor-iri.ts\`)
  could still ship extensionless imports. They're not in the lint
  scope. If one breaks at runtime we can extend the glob — for now
  they tend to be tiny utility modules that don't import other
  relatives.
- The deeper fix would be \`moduleResolution: nodenext\` for server-side
  tsconfig, or bundling the server code so Node never sees raw \`.ts\`.
  Bigger surgery; the lint rule covers the failure mode for now.

Full repo: pnpm typecheck / lint / test all green after \`pnpm install\`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 08:08:19 +02:00
..
auth fix(journal): fail loud in production when secrets are unset 2026-05-24 11:37:20 +02:00
connected-services chore(ts): eliminate the remaining 4 \as any\ casts in production code 2026-05-26 07:11:02 +02:00
notifications Merge /follows/requests into /notifications as a tabbed inbox 2026-04-26 08:24:59 +02:00
sync Deepen three architectural seams: FIT consolidation, host election extraction, injectable db 2026-05-10 15:52:31 +02:00
activities.server.ts fix(journal): remove ineffective dynamic imports 2026-05-24 12:05:08 +02:00
actor-iri.ts fix(journal): architectural audit omnibus 2026-05-24 10:28:33 +02:00
api-guard.server.test.ts fix: enforce Terms gate on bearer-token API requests 2026-05-08 01:59:28 +02:00
api-guard.server.ts fix: enforce Terms gate on bearer-token API requests 2026-05-08 01:59:28 +02:00
auth.server.ts fix(journal/auth): atomic magic-token consume to close TOCTOU 2026-05-24 12:17:42 +02:00
boss.server.ts fix(journal): remove ineffective dynamic imports 2026-05-24 12:05:08 +02:00
canView.test.ts Apply public-content-visibility: visibility flag + public profile 2026-04-19 09:11:39 +02:00
config.server.test.ts fix(journal): fail loud in production when secrets are unset 2026-05-24 11:37:20 +02:00
config.server.ts fix: add E2E opt-out for fail-loud secret/DB-URL guards 2026-05-24 11:45:09 +02:00
crypto.server.test.ts Add Komoot import with public (bio verification) and authenticated modes 2026-05-23 10:18:46 +02:00
crypto.server.ts Add Komoot import with public (bio verification) and authenticated modes 2026-05-23 10:18:46 +02:00
db.ts Deepen three architectural seams: FIT consolidation, host election extraction, injectable db 2026-05-10 15:52:31 +02:00
demo-bot.integration.test.ts ci: wire integration tests into the CI E2E job 2026-05-25 23:27:44 +02:00
demo-bot.server.ts Atomic GPX save: validate + persist row + geometry in one transaction 2026-05-10 15:02:56 +02:00
demo-bot.test.ts Apply configurable-demo-persona: per-instance demo identity + voice 2026-04-19 10:30:32 +02:00
email.server.test.ts Add observability: health endpoints, structured logging, metrics, Grafana stack 2026-03-26 22:59:44 +01:00
email.server.ts fix: extensionless server-side imports + lint rule to catch them 2026-05-26 08:08:19 +02:00
events.server.ts Implement notifications + supporting fixes 2026-04-26 01:28:55 +02:00
explore.integration.test.ts Include the demo persona on /explore so users can follow it 2026-04-26 11:43:24 +02:00
explore.server.ts Include the demo persona on /explore so users can follow it 2026-04-26 11:43:24 +02:00
follow.integration.test.ts Locked-account profiles: private = stub + Pending follow flow 2026-04-25 23:38:26 +02:00
follow.server.ts Merge /follows/requests into /notifications as a tabbed inbox 2026-04-26 08:24:59 +02:00
gpx-save.server.test.ts Atomic GPX save: validate + persist row + geometry in one transaction 2026-05-10 15:02:56 +02:00
gpx-save.server.ts Atomic GPX save: validate + persist row + geometry in one transaction 2026-05-10 15:02:56 +02:00
http.server.test.ts fix(journal): architectural audit omnibus 2026-05-24 10:28:33 +02:00
http.server.ts fix(journal): architectural audit omnibus 2026-05-24 10:28:33 +02:00
jwt.server.ts fix(journal): single-use JWT enforcement for route callback tokens (#2 Phase B) 2026-05-26 00:38:08 +02:00
komoot-bulk-import.server.ts Add background bulk import for Komoot 2026-05-23 18:19:10 +02:00
komoot.server.test.ts Add Komoot import with public (bio verification) and authenticated modes 2026-05-23 10:18:46 +02:00
komoot.server.ts fix(journal): architectural audit omnibus 2026-05-24 10:28:33 +02:00
legal.ts Apply public-content-visibility: visibility flag + public profile 2026-04-19 09:11:39 +02:00
logger.server.test.ts feat(journal): per-request requestId propagated through logs 2026-05-24 12:31:30 +02:00
logger.server.ts feat(journal): per-request requestId propagated through logs 2026-05-24 12:31:30 +02:00
metrics.server.ts Fix prom-client double-registration on prod 2026-04-19 10:44:57 +02:00
notifications.integration.test.ts Cursor-based pagination for /notifications 2026-04-26 01:42:32 +02:00
notifications.server.ts Cursor-based pagination for /notifications 2026-04-26 01:42:32 +02:00
oauth.server.test.ts Implement OAuth2 PKCE auth, discovery, and mobile API client 2026-04-13 00:41:40 +02:00
oauth.server.ts Drop auth.server.ts re-exports + rename to .server.ts convention (task 5.2) 2026-05-08 03:01:30 +02:00
operator.ts Add legal pages, ToS acceptance, and alpha banner 2026-04-18 00:08:48 +02:00
rate-limit.server.test.ts fix(journal): rate-limit auth endpoints 2026-05-24 11:51:43 +02:00
rate-limit.server.ts fix: bypass rate limiter when E2E=true 2026-05-24 11:57:01 +02:00
routes.server.ts ci: wire integration tests into the CI E2E job 2026-05-25 23:27:44 +02:00
sentry.client.ts fix(sentry): remove hardcoded DSN fallbacks; supply via env in CI 2026-05-25 23:07:07 +02:00