Skip to content

Adding Path Alias Support in fastify-cli #806

@logan272

Description

@logan272

Prerequisites

  • I have written a descriptive issue title
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions