ts-unused-exports
ts-unused-exports copied to clipboard
`ts-unused-exports` thinks my entire project is unused [.js extension]
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.
-
Package version: 8.0.0
-
Package installation location: Global, in
%appdata%\npm\node_modules
on myC:
drive. -
Project location: In
D:\xampp\htdocs\myproject
(I find placing the repo inside my webserver environment to be the most convenient way to debug my code) -
Command used:
ts-unused-exports tsconfig.json
fromD:\xampp\htdocs\myproject
-
Project
package.json
:{ "name": "myproject", "version": "1.0.0", "description": "", "main": "src/index.js", "scripts": { "test": "tsc && start http://localhost/html/" }, "author": "", "license": "ISC", "devDependencies": { "ts-standard": "^11.0.0", "typescript": "^4.7.4" } }
-
Project
tsconfig.json:
{ "compilerOptions": { "module": "es6", "target": "es2019", "noImplicitAny": false, "alwaysStrict": true, "removeComments": true, "strictNullChecks": true, "preserveConstEnums": true, "sourceMap": true, "outDir": "build" }, "include": ["src/**/*.ts"], "exclude": ["node_modules"] }
-
Import statement examples:
// Examples from index.ts import { Tile } from './Game/Entity/Tile.js' import { Player } from './Game/Entity/Actor/Player.js' // Example from Entity.ts import { Component } from '../Component/Component.js'
-
Project structure:
-
tsconfig.json
,package.json
,package-lock.json
,.eslintrc.json
,.eslintignore
,.gitignore
-
build/
folder, with all the.js
and.js.map
files generated when compiling. -
html/
folder, withindex.html
andmain.css
. -
src/
folder-
index.ts
-
Game/
folder-
Game.ts
-
Entity/
,Component/
,System/
,UI/
folders, etc. (I'm not going to list all of them or all their contents, but this should give a decent impression of my project structure.)
-
-
-
I'm sorry, but this title made me laugh. 😂
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 ...
- 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
ah - reading again.
The source is index.ts
not js
. ok!
update: added a itest to cover.
Fixed by #220. We released that in 8.0.2
Closing, unless new info comes in - thank you.