pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
749 stars 49 forks source link

`ts-unused-exports` thinks my entire project is unused [.js extension] #219

Closed gamesaucer closed 1 year ago

gamesaucer commented 2 years ago

As it says in the title, according the the command output, every single export from every file in my project is unused. However, it has many imports and compiles just fine, so something strange is going on here.
I don't know if this is a configuration error or a bug, but either way, I'll give as much detail as I can in the hope that someone can find the issue and fix it / tell me how to work around it.

EDIT: I think it's caused by using a .js extension in my imports, but this is still valid TS and it's necessary to generate working JS code (JS requires that imports have the full filename including the extension, and the TS compiler doesn't add it when absent). This is a major oversight if this is indeed the reason it doesn't work.

Cansiny0320 commented 2 years ago

I'm sorry, but this title made me laugh. 😂

mrseanryan commented 1 year ago

hi @gamesaucer

I've opened a PR that tries to reproduce the problem:

https://github.com/pzavolinsky/ts-unused-exports/pull/251

Indeed, including .js files is not something we currently support, but could be interesting to support it ...

I have a few questions - if we can work together, we can figure it out ...


  1. Normally to include .js files, tsc should be used with --alllowJs like:
npx tsc  --allowJs

For my PR, this mostly works - but does NOT copy over index.js. how do you get around this? or are you compiling some other way? 🤔

(my bad - I thought there was a index.js in src)


2. How is the index.js file executed? My understanding is, a JavaScript file that contains TypeScript cannot normally be run for example by Node or a browser... (it would need to be compiled to just JavaScript...)

(my bad - I thought there was a index.js in src)


thanks for your collaboration, sean

mrseanryan commented 1 year ago

ah - reading again.

The source is index.ts not js. ok!

mrseanryan commented 1 year ago

update: added a itest to cover.

Fixed by #220. We released that in 8.0.2

Closing, unless new info comes in - thank you.