{"id":16641800,"url":"https://github.com/samthor/esm-resolve","last_synced_at":"2025-11-05T20:03:30.700Z","repository":{"id":57230419,"uuid":"336708455","full_name":"samthor/esm-resolve","owner":"samthor","description":"Resolves ESM imports in Node","archived":false,"fork":false,"pushed_at":"2024-04-17T23:51:22.000Z","size":431,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-01T07:41:34.717Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/esm-resolve","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.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":"2021-02-07T05:27:16.000Z","updated_at":"2024-06-24T00:15:18.000Z","dependencies_parsed_at":"2024-10-31T23:45:49.185Z","dependency_job_id":null,"html_url":"https://github.com/samthor/esm-resolve","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":"0.13043478260869568","last_synced_commit":"c8e9155821bba6e54c8cc98c7828e5d622df54cf"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fesm-resolve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fesm-resolve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fesm-resolve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fesm-resolve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/esm-resolve/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244146352,"owners_count":20405819,"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":[],"created_at":"2024-10-12T07:47:55.218Z","updated_at":"2025-11-05T20:03:30.635Z","avatar_url":"https://github.com/samthor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/samthor/esm-resolve/workflows/Tests/badge.svg)](https://github.com/samthor/esm-resolve/actions)\n\nSync ESM import resolver for Node written in pure JS.\nThis is written to be part of an [ESM dev server](https://github.com/samthor/dhost) or build process.\nIt is permissive by default, allowing some cases which would normally be failures.\n\n⚠️ This resolver was writtem before [`import.meta.resolve()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve) was widely available\u0026mdash;it may work for you without adding _yet another_ dependency.\nHowever, \"esm-resolve\" is a bit more permissive.\n\n## Usage\n\nInstall and import \"esm-resolve\" via your favorite package manager.\nCreate a resolver based on the importing file.\n\n```js\nimport buildResolver from 'esm-resolve';\nimport { buildResolver } from 'esm-resolve'; // also works\n\nconst r = buildResolver('./lib/file.js');\n\nr('./relative'); // './relative.js'\nr('foo-test-package-name'); // '../node_modules/foo-test-package-name/index.js'\n```\n\nResolution logic is actually the same for any files in the same directory, so resolver objects can be reused (and they have a small bit of cache).\n\nThe resolved path is returned relative _to the importer_ of that file, not your process' current directory.\nYou can set the `resolveToAbsolute` option if you'd always like an absolute path.\n\n## Notes\n\nThis implements modern Node resolution, i.e., [subpath exports](https://nodejs.org/api/packages.html#packages_subpath_exports), [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) and [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports).\nBy default, it will rewrite to the \"browser\", \"import\" or \"default\" keys (not \"node\", as it's expected that you'll use this for browser builds).\n\nIt fails gracefully in many ways, including falling back to real paths if exports aren't defined.\nIt will also remove imports that point purely to \".d.ts\" files (you don't need to create [peer JS](https://whistlr.info/2021/check-js-with-ts/#import-your-types)).\n\nYou can [configure all these options](./types/external.d.ts) via the resolver's second argument, e.g.:\n\n```js\n// Resolves for Node, and allows .mjs files.\nconst r = buildResolver('./lib/file.js', {\n  constraints: 'node',\n  matchNakedMjs: true,\n});\n\n// If there's a file \"foo.mjs\", this will now work:\nr('./foo'); // './foo.mjs'\n\n// Or if we're importing package with a node constraint:\nr('node-only'); // '../node-modules/node-only/build-for-node.js'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fesm-resolve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fesm-resolve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fesm-resolve/lists"}