pzavolinsky / ts-unused-exports

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

using as library: Default export not working in projects with `"type": "module"` #263

Closed mon-jai closed 1 year ago

mon-jai commented 1 year ago

The default export for this package is not a function, as documented, but an object with its default key pointing to a function.

Maybe there is something wrong with tsconfig.json.

Minimal reproducible example

CodeSandbox: https://codesandbox.io/p/sandbox/intelligent-fast-57i5c2

Code:

import analyzeTsConfig from "ts-unused-exports";

console.log(analyzeTsConfig); // { default: [Function (anonymous)] }
console.log(analyzeTsConfig.default); // [Function (anonymous)]

try {
  const result = analyzeTsConfig("path/to/tsconfig.json"); // TypeError: analyzeTsConfig is not a function
} catch (e) {
  console.error(e);
}

Output:

{ default: [Function (anonymous)] }
[Function (anonymous)]
TypeError: analyzeTsConfig is not a function
    at file:///project/sandbox/index.js:7:18
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
mrseanryan commented 1 year ago

hi @mon-jai - thanks for the feedback.

At this point, changing the API seems a bit risky ...

Have handled this by improving the README and adding examples.

If you have more examples feel free to open a PR :)

mon-jai commented 1 year ago

Maybe we can change it in the next major release?

mrseanryan commented 1 year ago

hm well personally Id rather leave it, as changing will alter the API for some users, and it could cause more problems/disruption than it solves. Also there are more important issues…

But if you think its important, you could try fixing it and open a PR …