justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
876 stars 63 forks source link

tsc-alias incorrectly adds .js extension to a module from node_modules #197

Closed olalonde closed 3 months ago

olalonde commented 1 year ago

I have a file stripe.ts which imports the stripe module (npm install stripe). tsc-alias adds a .js extension to it for some reason.

// stripe.ts
import Stripe from "stripe"

becomes

// stripe.js
import Stripe from "stripe.js";
olalonde commented 1 year ago

Fixed with this:

{
  "compilerOptions": {
   // ...
  },
  "tsc-alias": {
    "debug": true,
    "verbose": true,
    "replacers": {
      "base-url": {
        "enabled": false
      }
    }
  }
}
olalonde commented 1 year ago

Reopening because that configuration broke some other stuff. I believe this is a bug.

if the module specifier is not a file path, tsc-alias shouldn't add a .js extension even if there is a file with that name.

olalonde commented 12 months ago

Ended up writing this: https://github.com/olalonde/tsc-module-loader

U-4-E-A commented 7 months ago

Was this by any chance where you had a file with the same name as something you were importing? In my case I had a file called react.ts of react tools with used import { useEffect, useRef, DependencyList, MutableRefObject, LegacyRef, RefCallback } from 'react'. tsc-alias is still converting this to 'react.js'.

melalj commented 4 months ago

Having the exact bug. It's shocking that tsc doesn't support the alias with the compiler out of the box.

U-4-E-A commented 4 months ago

Having the exact bug. It's shocking that tsc doesn't support the alias with the compiler out of the box.

It's not only that, there should also be an option for specifying the file extensions in the transpiled files, especially when you consider package.json exports demands that ESM and CJS files have different extensions.

The whole JS/CJS/ESM/node ecosystem is a mess TBH. It seems like an eternal process of trying to glue all the bits together.