M-Izadmehr / deadfile

Simple util to find unused files in any JavaScript project (ES5, ES6, React, Vue, ...)
https://m-izadmehr.github.io/deadfile/
372 stars 20 forks source link

Doesn't resolve directory aliases #19

Open SudoPlz opened 4 years ago

SudoPlz commented 4 years ago

Hey there,

in our project we use module-resolver with directory aliases, the config looks like this:

[
    "module-resolver",
    {
      "root": [
        "."
      ],
      "alias": {
        "~": "./src",
        "lib": "./src/lib",
        "components": "./src/components",
        "state": "./src/state",
        "config": "./src/config",
        "RootParams": "./src/lib/Shared/ScreenManager/RootParams"
      }
    }
  ]

but when running deadfile we get the following error:

err:  Error: Can't resolve './src' in '/Users/workstation/Development/example/mobile'
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:209:21
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at /Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/enhanced-resolve/lib/Resolver.js:285:5
    at eval (eval at create (/Users/workstation/.nvm/versions/node/v12.13.1/lib/node_modules/deadfile/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1) {
  details: "resolve './src' in '/Users/workstation/Development/example/mobile'\n" +
    '  using description file: /Users/workstation/Development/example/mobile/package.json (relative path: .)\n' +
    '    using description file: /Users/workstation/Development/example/mobile/package.json (relative path: ./src)\n' +
    '      no extension\n' +
    '        /Users/workstation/Development/example/mobile/src is not a file\n' +
    '      .js\n' +
    "        /Users/workstation/Development/example/mobile/src.js doesn't exist\n" +
    '      .jsx\n' +
    "        /Users/workstation/Development/example/mobile/src.jsx doesn't exist\n" +
    '      .ts\n' +
    "        /Users/workstation/Development/example/mobile/src.ts doesn't exist\n" +
    '      tsx\n' +
    "        /Users/workstation/Development/example/mobile/srctsx doesn't exist\n" +
    '      .vue\n' +
    "        /Users/workstation/Development/example/mobile/src.vue doesn't exist\n" +
    '      as directory\n' +
    '        existing directory\n' +
    '          using path: /Users/workstation/Development/example/mobile/src/index\n' +
    '            using description file: /Users/workstation/Development/example/mobile/package.json (relative path: ./src/index)\n' +
    '              no extension\n' +
    "                /Users/workstation/Development/example/mobile/src/index doesn't exist\n" +
    '              .js\n' +
    "                /Users/workstation/Development/example/mobile/src/index.js doesn't exist\n" +
    '              .jsx\n' +
    "                /Users/workstation/Development/example/mobile/src/index.jsx doesn't exist\n" +
    '              .ts\n' +
    "                /Users/workstation/Development/example/mobile/src/index.ts doesn't exist\n" +
    '              tsx\n' +
    "                /Users/workstation/Development/example/mobile/src/indextsx doesn't exist\n" +
    '              .vue\n' +
    "                /Users/workstation/Development/example/mobile/src/index.vue doesn't exist",
  missing: [
    '/Users/workstation/Development/example/mobile/src',
    '/Users/workstation/Development/example/mobile/src.js',
    '/Users/workstation/Development/example/mobile/src.jsx',
    '/Users/workstation/Development/example/mobile/src.ts',
    '/Users/workstation/Development/example/mobile/srctsx',
    '/Users/workstation/Development/example/mobile/src.vue',
    '/Users/workstation/Development/example/mobile/src/index',
    '/Users/workstation/Development/example/mobile/src/index.js',
    '/Users/workstation/Development/example/mobile/src/index.jsx',
    '/Users/workstation/Development/example/mobile/src/index.ts',
    '/Users/workstation/Development/example/mobile/src/indextsx',
    '/Users/workstation/Development/example/mobile/src/index.vue'
  ]
}

Looks like the problem is enhanced-resolver doesn't understand that /src refers to a directory (and not a file), and is trying to find a specific file in there.

Any ideas?

Thanks

zstuder25 commented 3 years ago

Any update on this?

angelod1as commented 3 years ago

Got this issue today.

danielcarvalho-hotmart commented 2 years ago

up 👀

eightHundreds commented 2 years ago

https://github.com/M-Izadmehr/deadfile/blob/ba8c6db1060d200a325dbea4ca70fdb8f5ab9035/src/models/Parsables.js?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L1

const defaultParsableExtensions = [".js", ".jsx", ".ts", "tsx", ".vue"];

tsx mabe missing .

leason-wan commented 2 years ago

Can support webpack config?

joepake commented 2 years ago

I encountered this issue and I resolved by this way:

Replace all import 'alias' to your absolute path. eg: '.src/' -> '/Users/workstation/Development/example/mobile/src/' Run deadfile command Delete all unused files Replace all absolute paths to your alias

steffenag97 commented 1 year ago

In our babel.config.js we have the following, which works like a charm 😃

alias: {
  client: path.resolve(__dirname, './client/')
}