tsc-alias icon indicating copy to clipboard operation
tsc-alias copied to clipboard

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

Open olalonde opened this issue 2 years ago • 6 comments

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 avatar Sep 01 '23 14:09 olalonde

Fixed with this:

{
  "compilerOptions": {
   // ...
  },
  "tsc-alias": {
    "debug": true,
    "verbose": true,
    "replacers": {
      "base-url": {
        "enabled": false
      }
    }
  }
}

olalonde avatar Sep 01 '23 14:09 olalonde

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 avatar Sep 03 '23 04:09 olalonde

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

olalonde avatar Sep 10 '23 16:09 olalonde

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'.

U-4-E-A avatar Feb 03 '24 23:02 U-4-E-A

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

melalj avatar Apr 30 '24 14:04 melalj

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.

U-4-E-A avatar May 09 '24 15:05 U-4-E-A