Skip to content

Imports with path aliases ignored #16

Open
@idudinov

Description

@idudinov

Hello, thanks for this library! Before knowing about it, I was giving up migrate my libs to ESM, mainly because of all import had to be upgraded. Now it's possible and doable, and I have successful examples.

However now I'm trying to migrate my app's codebase to ESM, and encountered a problem: import paths that start with aliases (both known to TS config and Node via module-alias package) are ignored on this line:

if (name.startsWith('node:') || !name.startsWith('/')) {
// e.g. 'node:fs/promises' or 'fs/promises'
return
}

I have 1k+ imports using path aliases like

import logger from 'common/logger'; // ../../common/logger.ts -> 'common/logger.js'
import * as utils from 'server/utils; // ./src/server/utils/index.ts -> 'server/utils/index.js'

and some of them are for /index.js files, some are just need to be updated with .js suffix – that's where this library shows its superpowers.

Not sure how it could be possible to let this library:

  1. to respect tsconfig's aliases, or be configured somehow to recognize aliases;
  2. then resolve files correctly according to the alias value;
  3. do the rest of the magic.

So maybe someone has a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions