{"id":13508858,"url":"https://github.com/webpack/enhanced-resolve","last_synced_at":"2025-12-12T00:11:34.295Z","repository":{"id":4272218,"uuid":"5400204","full_name":"webpack/enhanced-resolve","owner":"webpack","description":"Offers an async require.resolve function. It's highly configurable.","archived":false,"fork":false,"pushed_at":"2025-02-14T16:36:38.000Z","size":1427,"stargazers_count":962,"open_issues_count":29,"forks_count":193,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-08T04:08:54.718Z","etag":null,"topics":["commonjs","esm","javascript","resolve","resolver"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webpack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-08-13T14:45:48.000Z","updated_at":"2025-05-06T19:38:33.000Z","dependencies_parsed_at":"2023-07-05T19:48:40.047Z","dependency_job_id":"86583560-16bf-47ad-9af4-952130e1c036","html_url":"https://github.com/webpack/enhanced-resolve","commit_stats":{"total_commits":669,"total_committers":74,"mean_commits":9.04054054054054,"dds":0.5037369207772795,"last_synced_commit":"4fbcfa1c831858b495b7ac7835cb3a9f10496495"},"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-resolve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-resolve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-resolve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webpack%2Fenhanced-resolve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webpack","download_url":"https://codeload.github.com/webpack/enhanced-resolve/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252997999,"owners_count":21837922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commonjs","esm","javascript","resolve","resolver"],"created_at":"2024-08-01T02:00:59.523Z","updated_at":"2025-12-12T00:11:34.288Z","avatar_url":"https://github.com/webpack.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# enhanced-resolve\n\n[![npm][npm]][npm-url]\n[![Build Status][build-status]][build-status-url]\n[![codecov][codecov-badge]][codecov-url]\n[![Install Size][size]][size-url]\n[![GitHub Discussions][discussion]][discussion-url]\n\nOffers an async require.resolve function. It's highly configurable.\n\n## Features\n\n- plugin system\n- provide a custom filesystem\n- sync and async node.js filesystems included\n\n## Getting Started\n\n### Install\n\n```sh\n# npm\nnpm install enhanced-resolve\n# or Yarn\nyarn add enhanced-resolve\n```\n\n### Resolve\n\nThere is a Node.js API which allows to resolve requests according to the Node.js resolving rules.\nSync and async APIs are offered. A `create` method allows to create a custom resolve function.\n\n```js\nconst resolve = require(\"enhanced-resolve\");\n\nresolve(\"/some/path/to/folder\", \"module/dir\", (err, result) =\u003e {\n\tresult; // === \"/some/path/node_modules/module/dir/index.js\"\n});\n\nresolve.sync(\"/some/path/to/folder\", \"../../dir\");\n// === \"/some/path/dir/index.js\"\n\nconst myResolve = resolve.create({\n\t// or resolve.create.sync\n\textensions: [\".ts\", \".js\"],\n\t// see more options below\n});\n\nmyResolve(\"/some/path/to/folder\", \"ts-module\", (err, result) =\u003e {\n\tresult; // === \"/some/node_modules/ts-module/index.ts\"\n});\n```\n\n### Creating a Resolver\n\nThe easiest way to create a resolver is to use the `createResolver` function on `ResolveFactory`, along with one of the supplied File System implementations.\n\n```js\nconst fs = require(\"fs\");\nconst { CachedInputFileSystem, ResolverFactory } = require(\"enhanced-resolve\");\n\n// create a resolver\nconst myResolver = ResolverFactory.createResolver({\n\t// Typical usage will consume the `fs` + `CachedInputFileSystem`, which wraps Node.js `fs` to add caching.\n\tfileSystem: new CachedInputFileSystem(fs, 4000),\n\textensions: [\".js\", \".json\"],\n\t/* any other resolver options here. Options/defaults can be seen below */\n});\n\n// resolve a file with the new resolver\nconst context = {};\nconst lookupStartPath = \"/Users/webpack/some/root/dir\";\nconst request = \"./path/to-look-up.js\";\nconst resolveContext = {};\nmyResolver.resolve(\n\tcontext,\n\tlookupStartPath,\n\trequest,\n\tresolveContext,\n\t(err /* Error */, filepath /* string */) =\u003e {\n\t\t// Do something with the path\n\t},\n);\n```\n\n#### Resolver Options\n\n| Field            | Default                     | Description                                                                                                                                               |\n| ---------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| alias            | []                          | A list of module alias configurations or an object which maps key to value                                                                                |\n| aliasFields      | []                          | A list of alias fields in description files                                                                                                               |\n| extensionAlias   | {}                          | An object which maps extension to extension aliases                                                                                                       |\n| cachePredicate   | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties.             |\n| cacheWithContext | true                        | If unsafe cache is enabled, includes `request.context` in the cache key                                                                                   |\n| conditionNames   | []                          | A list of exports field condition names                                                                                                                   |\n| descriptionFiles | [\"package.json\"]            | A list of description files to read from                                                                                                                  |\n| enforceExtension | false                       | Enforce that a extension from extensions must be used                                                                                                     |\n| exportsFields    | [\"exports\"]                 | A list of exports fields in description files                                                                                                             |\n| extensions       | [\".js\", \".json\", \".node\"]   | A list of extensions which should be tried for files                                                                                                      |\n| fallback         | []                          | Same as `alias`, but only used if default resolving fails                                                                                                 |\n| fileSystem       |                             | The file system which should be used                                                                                                                      |\n| fullySpecified   | false                       | Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests) |\n| mainFields       | [\"main\"]                    | A list of main fields in description files                                                                                                                |\n| mainFiles        | [\"index\"]                   | A list of main files in directories                                                                                                                       |\n| modules          | [\"node_modules\"]            | A list of directories to resolve modules from, can be absolute path or folder name                                                                        |\n| plugins          | []                          | A list of additional resolve plugins which should be applied                                                                                              |\n| resolver         | undefined                   | A prepared Resolver to which the plugins are attached                                                                                                     |\n| resolveToContext | false                       | Resolve to a context instead of a file                                                                                                                    |\n| preferRelative   | false                       | Prefer to resolve module requests as relative request and fallback to resolving as module                                                                 |\n| preferAbsolute   | false                       | Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots                                                          |\n| restrictions     | []                          | A list of resolve restrictions                                                                                                                            |\n| roots            | []                          | A list of root paths                                                                                                                                      |\n| symlinks         | true                        | Whether to resolve symlinks to their symlinked location                                                                                                   |\n| unsafeCache      | false                       | Use this cache object to unsafely cache the successful requests                                                                                           |\n\n## Plugins\n\nSimilar to `webpack`, the core of `enhanced-resolve` functionality is implemented as individual plugins that are executed using [`tapable`](https://github.com/webpack/tapable).\nThese plugins can extend the functionality of the library, adding other ways for files/contexts to be resolved.\n\nA plugin should be a `class` (or its ES5 equivalent) with an `apply` method. The `apply` method will receive a `resolver` instance, that can be used to hook in to the event system.\n\n### Plugin Boilerplate\n\n```js\nclass MyResolverPlugin {\n\tconstructor(source, target) {\n\t\tthis.source = source;\n\t\tthis.target = target;\n\t}\n\n\tapply(resolver) {\n\t\tconst target = resolver.ensureHook(this.target);\n\t\tresolver\n\t\t\t.getHook(this.source)\n\t\t\t.tapAsync(\"MyResolverPlugin\", (request, resolveContext, callback) =\u003e {\n\t\t\t\t// Any logic you need to create a new `request` can go here\n\t\t\t\tresolver.doResolve(target, request, null, resolveContext, callback);\n\t\t\t});\n\t}\n}\n```\n\nPlugins are executed in a pipeline, and register which event they should be executed before/after. In the example above, `source` is the name of the event that starts the pipeline, and `target` is what event this plugin should fire, which is what continues the execution of the pipeline. For an example of how these different plugin events create a chain, see `lib/ResolverFactory.js`, in the `//// pipeline ////` section.\n\n## Escaping\n\nIt's allowed to escape `#` as `\\0#` to avoid parsing it as fragment.\n\nenhanced-resolve will try to resolve requests containing `#` as path and as fragment, so it will automatically figure out if `./some#thing` means `.../some.js#thing` or `.../some#thing.js`. When a `#` is resolved as path it will be escaped in the result. Here: `.../some\\0#thing.js`.\n\n## Tests\n\n```sh\nyarn test\n```\n\n## Passing options from webpack\n\nIf you are using `webpack`, and you want to pass custom options to `enhanced-resolve`, the options are passed from the `resolve` key of your webpack configuration e.g.:\n\n```\nresolve: {\n  extensions: ['.js', '.jsx'],\n  modules: [path.resolve(__dirname, 'src'), 'node_modules'],\n  plugins: [new DirectoryNamedWebpackPlugin()]\n  ...\n},\n```\n\n## License\n\nCopyright (c) 2012-2019 JS Foundation and other contributors\n\nMIT (http://www.opensource.org/licenses/mit-license.php)\n\n[npm]: https://img.shields.io/npm/v/enhanced-resolve.svg\n[npm-url]: https://www.npmjs.com/package/enhanced-resolve\n[build-status]: https://github.com/webpack/enhanced-resolve/actions/workflows/test.yml/badge.svg\n[build-status-url]: https://github.com/webpack/enhanced-resolve/actions\n[codecov-badge]: https://codecov.io/gh/webpack/enhanced-resolve/branch/main/graph/badge.svg?token=6B6NxtsZc3\n[codecov-url]: https://codecov.io/gh/webpack/enhanced-resolve\n[size]: https://packagephobia.com/badge?p=enhanced-resolve\n[size-url]: https://packagephobia.com/result?p=enhanced-resolve\n[discussion]: https://img.shields.io/github/discussions/webpack/webpack\n[discussion-url]: https://github.com/webpack/webpack/discussions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpack%2Fenhanced-resolve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebpack%2Fenhanced-resolve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebpack%2Fenhanced-resolve/lists"}