eslint-import-resolver-typescript
eslint-import-resolver-typescript copied to clipboard
Typescript NodeNext path alias with extension
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?
I forgot to add that Typescript correctly resolves to the file, so this isn't an issue with the alias specification.
If you still have any issue, please provide a runnable reproduction.
@JounQin Pretty simple case: https://github.com/WoodyWoodsta/repro-eslint-import-resolver-typescript-191
@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.
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.
The fix is easy:
{
"paths": {
"alias": ["path/to/specific/file.mts"]
}
}
@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.