eslint-plugin-require-extensions icon indicating copy to clipboard operation
eslint-plugin-require-extensions copied to clipboard

TypeScript paths

Open carlocorradini opened this issue 2 years ago • 8 comments

When using custom TypeScript paths the import is completely ignored (and therefore ESM invalid):

import { hello } from "@/world"; // IGNORED!
import { test } from "@/world/wow" // IGNORED!

Correct behaviour:

import { hello } from "@/world/index.js";
import { test } from "@/world/wow.js"

There is the need to understand if the import path points to a folder or a file and then apply the corresponding logic.

carlocorradini avatar Mar 27 '23 09:03 carlocorradini

I was so happy when I found this, for converting a large existing repo, but then I realized that most of my paths use aliases 😞

0x80 avatar Nov 13 '23 19:11 0x80

Happy to accept a PR to fix this!

jordaaash avatar Nov 13 '23 19:11 jordaaash

I don't think it's an easy fix. I tried hacking my way around it, but it didn't work, and I ran out of time. I'm going to park this for now.

0x80 avatar Nov 13 '23 21:11 0x80

same issue, hope someone have a good idea.

Val-istar-Guo avatar Dec 03 '23 13:12 Val-istar-Guo

@jordaaash Would you accept a PR which adds an ability to specify alias mapping for your two rules? Similar to these two: eslint-import-resolver-custom-alias and eslint-import-resolver-alias.

Ideally, it would take the list of aliases from any of these:

  • package.json browser field
  • webpack conf resolve.alias field
  • tsconfig.json paths but that would be much more complicated to implement.

mbonaci avatar May 07 '24 11:05 mbonaci

FYI just to report that I managed to do a rewrite in which the existing import resolution aliases (webpack, jsconfig, tsconfig...) are taken into account. I decided to publish a new package, given the unresponsiveness here, although I have to thank the original authors for the inspiration.

Introducing eslint-plugin-esm-import plugin: https://github.com/sematext/eslint-plugin-esm-import

mbonaci avatar May 09 '24 17:05 mbonaci

@mbonaci Sorry about that! I had some of my Github emails going to an old work email address for quite a while, so I didn't see the notifications here until yours this week. I'd be happy to accept a PR to fix this behavior, and I'll check out your new package as well. If there's an opportunity for us to consolidate I'm very open to it, as we haven't been updating this in some time.

jordaaash avatar May 09 '24 17:05 jordaaash

@jordaaash No worries.

If there's an opportunity for us to consolidate...

I'd be open to that. You can ping me here when you check it out.

mbonaci avatar May 10 '24 13:05 mbonaci