eslint-import-resolver-typescript icon indicating copy to clipboard operation
eslint-import-resolver-typescript copied to clipboard

Typescript NodeNext path alias with extension

Open WoodyWoodsta opened this issue 1 year ago • 7 comments

I have a typescript project with moduleResolution: 'NodeNext'. In my tsconfig.json, I have set up an alias which points directly to a file. In the ES spec, this would be with the file extension, and thus should be in the alias target:

tsconfig.json

{
	"paths": {
		"alias": ["path/to/specific/file.mjs"]
	}
}

Eslint complains, if I try:

import something from 'alias';

with "Unable to resolve path to module 'alias'".

Am I configuring this incorrectly, or is this not yet supported?

WoodyWoodsta avatar Oct 10 '22 16:10 WoodyWoodsta

I forgot to add that Typescript correctly resolves to the file, so this isn't an issue with the alias specification.

WoodyWoodsta avatar Oct 10 '22 16:10 WoodyWoodsta

If you still have any issue, please provide a runnable reproduction.

JounQin avatar Oct 11 '22 00:10 JounQin

@JounQin Pretty simple case: https://github.com/WoodyWoodsta/repro-eslint-import-resolver-typescript-191

WoodyWoodsta avatar Oct 11 '22 08:10 WoodyWoodsta

@JounQin Did you manage to have a look at the reproduction above?

I'm experiencing the same issue on v3.6.1. It also seems related to https://github.com/import-js/eslint-import-resolver-typescript/issues/234.

mackermans avatar Jan 12 '24 14:01 mackermans

Sorry, I've totally forgotten about this issue, I'll take a look when I'm free at this weekend, or you can help to debug first.

JounQin avatar Jan 12 '24 14:01 JounQin

The fix is easy:

{
	"paths": {
		"alias": ["path/to/specific/file.mts"]
	}
}

EdisonSu768 avatar Jan 16 '24 03:01 EdisonSu768

@EdisonSu768 Maybe we can support auto mapping which is the behavior of TypeScript itself.

See https://github.com/import-js/eslint-import-resolver-typescript/blob/acaaddd73cc457a5e5a36811fede771a0ab2d5f2/src/index.ts#L59

Use options.extensionAlias for this purpose.

JounQin avatar Jan 16 '24 04:01 JounQin