Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Unable to find unimported files #41

Closed
dabyland opened this issue Jul 14, 2021 · 10 comments
Closed

Unable to find unimported files #41

dabyland opened this issue Jul 14, 2021 · 10 comments
Labels
question support questions

Comments

@dabyland
Copy link

First off, I apologize if this is not the preferred channel of communication for these "issues".

I've got Unimported running through my codebases at this point, properly finding unused dependencies. However I am unable to get it to find my unused files. I've even created new files to see if they will be detected but no luck. All of our files are just .js extensions. Before adding the aliases to my config, I did have unresolved imports, since those issues are fixed I believed it would be able to find my files.

Here is what my current config looks like:

.unimportedrc.json

{
	"entry": ["apps/manager/src/index.js"],
	"extensions": [".js"],
	"ignorePatterns": ["**/node_modules/**"],
	"ignoreUnresolved": ["some-npm-dependency"],
	"ignoreUnimported": ["src/i18n/locales/en.ts", "src/i18n/locales/nl.ts"],
	"ignoreUnused": ["create-emotion", "unimported"],
	"aliases": {
		"~/*": ["apps/manager/src/*"],
		"Lib/*": ["lib/node/src/*"],
		"ROOT":  ["./../../*"]
	}
}

My Output

Screen Shot 2021-07-14 at 2 52 38 PM

If there's a more appropriate area or contact for these general questions, please let me know.

Thanks in advance,
Danny

@smeijer smeijer added the question support questions label Jul 14, 2021
@jesseteal
Copy link

I think I'm having similar issues in that it doesn't appear to be recognizing or respecting my aliases. This may be due to a caching issue.

Try running

rm node_modules/.cache/unimported

and then re-running unimported.

@dabyland
Copy link
Author

@jesseteal After you ran that, did it find your unimported files?

@jesseteal
Copy link

jesseteal commented Jul 27, 2021

I had the reverse problem. It wouldn't stop telling me that files were unimported even though they were. I didn't have aliases set up on the first run and it reported 500 unimported files. I added the proper alias but it continued to incorrectly report them. After clearing the cache file it dropped the unimported list to 157.

Have you tried changing your aliases to use relative paths? Like:

"~/*": ["./apps/manager/src/*"],
"Lib/*": ["./lib/node/src/*"],
...

I think it might be trying to turn your aliases into paths relative to the disk root. So instead of /Users/dabyland/RepoFolder/project/apps/manager/src/* you are getting /apps/manager/src/*

@smeijer
Copy link
Owner

smeijer commented Jul 27, 2021

@jesseteal are you using 1.12? Do you have the same trouble when 1.11?

I see in the screenshot that @dabyland is using 1.11. The cache has been introduced by 1.12. So that can't be the issue.

Incorrect mapping of aliases sounds more likely.

@smeijer
Copy link
Owner

smeijer commented Jul 27, 2021

Any chance you can make a small repo @dabyland?

@dabyland
Copy link
Author

@smeijer Here is a very basic version of the repo that I was having issues with. I created a couple of files in this one, one of which is imported and the other is not. It doesn't seem to be catching that but again, I'm sure there's something I'm missing here. It is however catching my unused dependencies.

@smeijer
Copy link
Owner

smeijer commented Jul 28, 2021

Figured it out. Thanks for the repo, that helped a lot!

So, the first thing in your repo that got me, was having a capital I in the filename of Index.js, while it's named index.js in an entry file in the config.

Next, and that's a bug in unimported, you only have a single extension specified in your config under the extensions property. I'm going to push a fix soon. In the mean while, you can check by just adding another extension there as well ([".js", ".ts"] for example).

@smeijer
Copy link
Owner

smeijer commented Jul 28, 2021

Ok, new version has been published. Can you give it a shot and let me know if it worked? This is the output I get on your test project: (after renaming Index.js to index.js)

image

@dabyland
Copy link
Author

Works like a charm, thanks for all the help and amazing tool!

@smeijer
Copy link
Owner

smeijer commented Jul 28, 2021

Sweet!

@smeijer smeijer closed this as completed Jul 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question support questions
Projects
None yet
Development

No branches or pull requests

3 participants