{"id":19444,"library":"directory-named-webpack-plugin","title":"directory-named-webpack-plugin","description":"Webpack resolve plugin that allows using a file named after its directory (e.g., foo/foo.js) instead of index.js as the entry point for directory imports. v4.1.0 supports Webpack >=4, with v2.x for Webpack 2/3 and v1.x for Webpack 1. Configurable via options like honorIndex, honorPackage, exclude, include, transformFn, and resolverHook. Provides fine-grained control over resolve behavior per directory, overcoming the limitation of always using index files.","status":"active","version":"4.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/shaketbaby/directory-named-webpack-plugin","tags":["javascript","webpack","plugin"],"install":[{"cmd":"npm install directory-named-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add directory-named-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add directory-named-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: works with webpack >=4.0.0","package":"webpack","optional":false}],"imports":[{"note":"This package does not provide a default ESM export; use CommonJS require(). For webpack config files, CommonJS is standard.","wrong":"import DirectoryNamedWebpackPlugin from 'directory-named-webpack-plugin';","symbol":"DirectoryNamedWebpackPlugin","correct":"const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');"},{"note":"ESM named import does not work because the package exports only as module.exports. Use default import via dynamic import.","wrong":"const { DirectoryNamedWebpackPlugin } = await import('directory-named-webpack-plugin');","symbol":"DirectoryNamedWebpackPlugin","correct":"const { default: DirectoryNamedWebpackPlugin } = await import('directory-named-webpack-plugin');"},{"note":"Constructor accepts either a boolean (honorIndex shorthand) or an options object. Using a boolean may be confusing; prefer options object for clarity.","wrong":"new DirectoryNamedWebpackPlugin(true)","symbol":"new DirectoryNamedWebpackPlugin()","correct":"new DirectoryNamedWebpackPlugin({ honorIndex: true })"}],"quickstart":{"code":"const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');\n\nmodule.exports = {\n  resolve: {\n    plugins: [\n      new DirectoryNamedWebpackPlugin({\n        honorIndex: false,\n        exclude: /node_modules/,\n        include: [\n          path.resolve(__dirname, 'src/components'),\n          path.resolve(__dirname, 'src/containers')\n        ]\n      })\n    ]\n  }\n};","lang":"javascript","description":"CommonJS webpack config using DirectoryNamedWebpackPlugin with exclude and include options."},"warnings":[{"fix":"Use v2.x for webpack 2/3, v1.x for webpack 1.","message":"v4.x requires webpack >=4.0.0. Using with webpack 2 or 3 will fail.","severity":"breaking","affected_versions":">=4.0.0 <5.0.0"},{"fix":"new DirectoryNamedWebpackPlugin({ honorIndex: true })","message":"By default, honorIndex is false, so index files are ignored. If you expect index.js to be used as fallback, set honorIndex: true.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add exclude: /node_modules/ or specify include paths to restrict scope.","message":"If exclude does not cover node_modules, the plugin will also apply to external packages, potentially causing unexpected resolve behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use new DirectoryNamedWebpackPlugin({ honorIndex: true }) instead of new DirectoryNamedWebpackPlugin(true).","message":"Using a boolean argument instead of options object is deprecated in favor of the options object.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Only change resolverHook if you understand webpack's resolver plugins deeply.","message":"The resolverHook option defaults to 'before-existing-directory'. Changing it to a different hook may cause the plugin to not work as expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Set honorIndex: false or ensure the directory has a file named after it. Check include/exclude settings.","cause":"DirectoryNamedWebpackPlugin is not resolving the desired file because honorIndex is true and index.js exists, or include/exclude is misconfigured.","error":"Error: Cannot find module 'foo' from 'bar'"},{"fix":"Use require('directory-named-webpack-plugin') or dynamic import with default property: const { default: DirNamedPlugin } = await import('directory-named-webpack-plugin')","cause":"Using ESM import incorrectly. This package is not an ESM default export.","error":"TypeError: DirectoryNamedWebpackPlugin is not a constructor"},{"fix":"Update the plugin to latest version or use resolverHook: 'directory' or 'resolve' as fallback (check webpack docs).","cause":"Webpack removed or renamed the resolver hook used by default.","error":"Error: Hook 'before-existing-directory' is not supported (webpack deprecation)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}