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

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

Closed
gamesaucer opened this issue Jul 28, 2022 · 4 comments
Closed
Labels
enhancement help wanted need-more-info We need more information before we can process the issue

Comments

@gamesaucer
Copy link

gamesaucer commented Jul 28, 2022

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 my C: 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 from D:\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, with index.html and main.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.)
@Cansiny0320
Copy link

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

@mrseanryan mrseanryan changed the title ts-unused-exports thinks my entire project is unused. ts-unused-exports thinks my entire project is unused [.js extension] Sep 10, 2022
@mrseanryan mrseanryan pinned this issue Sep 10, 2022
@mrseanryan
Copy link
Collaborator

mrseanryan commented Dec 10, 2022

hi @gamesaucer

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

#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 mrseanryan added enhancement need-more-info We need more information before we can process the issue and removed bug labels Dec 10, 2022
@mrseanryan
Copy link
Collaborator

ah - reading again.

The source is index.ts not js. ok!

mrseanryan added a commit that referenced this issue Dec 10, 2022
Add itest to cover use of JS files
@mrseanryan
Copy link
Collaborator

update: added a itest to cover.

Fixed by #220. We released that in 8.0.2

Closing, unless new info comes in - thank you.

@mrseanryan mrseanryan unpinned this issue Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted need-more-info We need more information before we can process the issue
Projects
None yet
Development

No branches or pull requests

3 participants