pacocoursey / next-unused

Find unused files in your Next.js projects
421 stars 15 forks source link

Every file reported as being unused #6

Closed howells closed 3 years ago

howells commented 3 years ago

Hi! It seems the script reports everything as being unused in my project, using the following config:

"next-unused": {
    "debug": true,
    "include": [
      "pages",
      "components",
      "queries",
      "stores",
      "contexts",
      "hooks"
    ],
    "entrypoints": [
      "pages"
    ]
  }
[debug] Found include config: pages,components,queries,stores,contexts,hooks
[debug] Found entrypoints config: pages
[debug] Using exclude regex: /^(?!(pages|components|queries|stores|contexts|hooks))/i and
[debug] Searching directories: [
  "/Users/***/client/pages",
  "/Users/d***/client/components",
  "/Users/***/client/queries",
  "/Users/***/client/stores",
  "/Users/***/client/contexts",
  "/Users/***/client/hooks"
]
[debug] Found entrypoints
[
  'pages/[...slug].js',
  'pages/_app.js',
  'pages/_document.js',
  'pages/api/checkout.js',
  'pages/api/preview/[...slug].js',
  'pages/api/preview/article.js',
  'pages/articles/[slug].js',
  'pages/articles/index.js',
  'pages/events/[slug].js',
  'pages/events/index.js',
  'pages/index.js'
]
Found 72 unused files:

[lists all 72 files in the directories]

I have this set in jsconfig, if that might make a difference, but otherwise everything is pretty normally set up:

"compilerOptions": {
    "baseUrl": "."
  }
pacocoursey commented 3 years ago

next-unused doesn't consider the baseUrl property yet. So if your import paths are absolute (import X from 'components/x') you'll have to treat it as an alias:

{
  "debug": true,
  "alias": {
    "components": "components/"
  }

Let me know if that works.

howells commented 3 years ago

@pacocoursey perfect! Thanks a lot, super useful tool