shaketbaby / directory-named-webpack-plugin

A Webpack plugin that treats a file with the name of directory as the index file
MIT License
182 stars 17 forks source link

Doesn't work without package.json #63

Open mariusrak opened 11 months ago

mariusrak commented 11 months ago

I used this package on Windows and everything works fine.

But when I use it on mac there is a problem. Folders that does not have package.json causes errors and they behave as if they didn't exists. But on windows it doesn't happen.

ERROR in ./index.js 7:16-45
Module not found: Error: Can't resolve './Main' in '/Users/.../Project'
resolve './Main' in '/Users/.../Project'
  No description file found in /Users/.../Projector above
  No description file found in /Users/.../Projector above
  no extension
    /Users/../Project/Main is not a file
  .*
    /Users/.../Project/Main.* doesn't exist
  .js
    /Users/.../Project/Main.js doesn't exist
  .jsx
    /Users/.../Project/Main.jsx doesn't exist
  as directory
    existing directory /Users/.../Project/Main
      No description file found in /Users/.../Project/Main or above
      using path: /Users/.../Project/Main/index
        No description file found in /Users/.../Project/Main or above
        no extension
          /Users/.../Project/Main/index doesn't exist
        .*
          /Users/.../Project/Main/index.* doesn't exist
        .js
          /Users/.../Project/Main/index.js doesn't exist
        .jsx
          /Users/.../Project/Main/index.jsx doesn't exist
 @ ./_canny/Application/File.js 10:0-32 299:12-18
 @ ./_canny/index.js 16:10-47

When I change /Main/Main.js to /Main/index.js. Or with /Main/Main.js I create package.json, everything works.

Could this be fixed by the plugin? Thanks

mariusrak commented 11 months ago

So I went into code and changed the hook before-existing-directory to existing-directory and it works. Seems like on mac for some reason a directory is only considered existing if there also exists the package.json file. So can we change the hook?

mariusrak commented 11 months ago

Sorry, after a day of debugging I found out it's not about mac or windows. It's just that on windows I have mistakenly some package.json somewhere in disk root. So after I created a package.json for project, it works. However, I don't need this package.json in the root (I have somewhat special project structure).

But I think, that this functionality should not depend on some random package.json, that doesn't belong to the directory that has named index instead of real index.js. So would it be possible to tap it on some other hook?

shaketbaby commented 11 months ago

package.json is significant for a nodejs project. The behaviour of some tools are different whether it exists or not. I'm not sure about your project structure and the configurations. What version of Webpack are you using? Are you able to provide some more info about your setup?

shaketbaby commented 11 months ago

I don't know if we can just tap into a different hook. Need to be careful as changing that could break some project unknowingly. If you are certain that tapping to existing-directory instead solves the problem; then I can make the hook configurable via a new option. You can then override the hook in your configuration.

mariusrak commented 11 months ago

Hi, yes, of course package.json is important file, but it's non-existence doesn't mean, that directory doesn't exists.

I tried to copy the plugin code and tap it to some other hook (I guess it was directory), but that didn't work. I'm not sure if there was some other issue. So I'm not sure which hook we should use. I guess you have more experience in this.

But making it configurable would be great.

shaketbaby commented 11 months ago

Have released a new version 4.1.0, the hook can be configured via option resolverHook.