Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olalonde opened this issue Sep 1, 2023 · 6 comments
Closed

Comments

@olalonde
Copy link

olalonde commented Sep 1, 2023

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
Copy link
Author

olalonde commented Sep 1, 2023

Fixed with this:

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

@olalonde olalonde closed this as completed Sep 1, 2023
@olalonde
Copy link
Author

olalonde commented Sep 3, 2023

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 olalonde reopened this Sep 3, 2023
@olalonde
Copy link
Author

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

@U-4-E-A
Copy link

U-4-E-A commented Feb 3, 2024

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
Copy link

melalj commented Apr 30, 2024

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
Copy link

U-4-E-A commented May 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants