fastify-cli icon indicating copy to clipboard operation
fastify-cli copied to clipboard

Adding Path Alias Support in fastify-cli

Open logan272 opened this issue 9 months ago • 0 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I'm working on a Fastify application created with the Fastify CLI, and I would like to add support for path aliases.

Currently, I have to use long relative paths like this:

import { hello } from '../../../hello.js';

It would be much more convenient to use a path alias, allowing me to write:

import { hello } from '@/hello.js';

I've configured my tsconfig.json as follows to set the path alias:

{
  "extends": "fastify-tsconfig",
  "compilerOptions": {
    "outDir": "dist",
    "strict": true,
    "strictNullChecks": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "target": "ES2022",
    "esModuleInterop": true,
    "baseUrl": "src",
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["src/**/*.ts"]
}

However, I'm unsure how to pass options to node itself when using the Fastify CLI to start my app.

For reference, here is a related discussion on Stack Overflow: ESM does not resolve module-alias.

Motivation

No response

Example

No response

logan272 avatar Mar 23 '25 05:03 logan272