{"id":13724941,"url":"https://github.com/wooorm/import-meta-resolve","last_synced_at":"2025-05-16T06:07:05.700Z","repository":{"id":38023270,"uuid":"367313586","full_name":"wooorm/import-meta-resolve","owner":"wooorm","description":"Resolve things like Node.js — ponyfill for `import.meta.resolve`","archived":false,"fork":false,"pushed_at":"2024-06-01T02:11:57.000Z","size":136,"stargazers_count":133,"open_issues_count":0,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-14T16:59:51.441Z","etag":null,"topics":["esm","module","node","resolve"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","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},"funding":{"github":"wooorm"}},"created_at":"2021-05-14T09:26:27.000Z","updated_at":"2025-05-10T01:31:13.000Z","dependencies_parsed_at":"2024-03-12T12:55:18.491Z","dependency_job_id":"9c418839-8ea2-4b1a-bf32-082e2174b877","html_url":"https://github.com/wooorm/import-meta-resolve","commit_stats":{"total_commits":66,"total_committers":6,"mean_commits":11.0,"dds":0.0757575757575758,"last_synced_commit":"5810176d9a9d6277c11f582de0d57b4243af8655"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fimport-meta-resolve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fimport-meta-resolve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fimport-meta-resolve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fimport-meta-resolve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/import-meta-resolve/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478190,"owners_count":22077676,"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":["esm","module","node","resolve"],"created_at":"2024-08-03T01:02:07.498Z","updated_at":"2025-05-16T06:07:00.656Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":["JavaScript"],"sub_categories":[],"readme":"# import-meta-resolve\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n\nResolve things like Node.js.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When to use this?](#when-to-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`resolve(specifier, parent)`](#resolvespecifier-parent)\n  * [`moduleResolve(specifier, parent, conditions, preserveSymlinks)`](#moduleresolvespecifier-parent-conditions-preservesymlinks)\n  * [`ErrnoException`](#errnoexception)\n* [Algorithm](#algorithm)\n* [Differences to Node](#differences-to-node)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a ponyfill for [`import.meta.resolve`][native-resolve].\nIt supports everything you need to resolve files just like modern Node does:\nimport maps, export maps, loading CJS and ESM projects, all of that!\n\n## When to use this?\n\nAs of Node.js 20.0, `import.meta.resolve` is still behind an experimental flag.\nThis package can be used to do what it does in Node 16–20.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install import-meta-resolve\n```\n\n## Use\n\n```js\nimport {resolve} from 'import-meta-resolve'\n\n// A file:\nconsole.log(resolve('./index.js', import.meta.url))\n//=\u003e file:///Users/tilde/Projects/oss/import-meta-resolve/index.js\n\n// A CJS package:\nconsole.log(resolve('builtins', import.meta.url))\n//=\u003e file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/builtins/index.js\n\n// A scoped CJS package:\nconsole.log(resolve('@eslint/eslintrc', import.meta.url))\n//=\u003e file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/@eslint/eslintrc/lib/index.js\n\n// A package with an export map:\nconsole.log(resolve('micromark/lib/parse', import.meta.url))\n//=\u003e file:///Users/tilde/Projects/oss/import-meta-resolve/node_modules/micromark/lib/parse.js\n\n// A node builtin:\nconsole.log(resolve('fs', import.meta.url))\n//=\u003e node:fs\n```\n\n## API\n\nThis package exports the identifiers [`moduleResolve`][moduleresolve] and\n[`resolve`][resolve].\nThere is no default export.\n\n### `resolve(specifier, parent)`\n\nMatch `import.meta.resolve` except that `parent` is required (you can pass\n`import.meta.url`).\n\n###### Parameters\n\n* `specifier` (`string`)\n  — the module specifier to resolve relative to parent\n  (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc)\n* `parent` (`string`, example: `import.meta.url`)\n  — the absolute parent module URL to resolve from; you must pass\n  `import.meta.url` or something else\n\n###### Returns\n\nFull `file:`, `data:`, or `node:` URL (`string`) to the found thing\n\n###### Throws\n\nThrows an [`ErrnoException`][errnoexception].\n\n### `moduleResolve(specifier, parent, conditions, preserveSymlinks)`\n\nThe [“Resolver Algorithm Specification”][algo] as detailed in the Node docs\n(which is slightly lower-level than `resolve`).\n\n###### Parameters\n\n* `specifier` (`string`)\n  — `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc\n* `parent` (`URL`, example: `import.meta.url`)\n  — full URL (to a file) that `specifier` is resolved relative from\n* `conditions` (`Set\u003cstring\u003e`, default: `new Set(['node', 'import'])`)\n  — conditions\n* `preserveSymlinks` (`boolean`, default: `false`)\n  — keep symlinks instead of resolving them\n\n###### Returns\n\nA URL object (`URL`) to the found thing.\n\n###### Throws\n\nThrows an [`ErrnoException`][errnoexception].\n\n### `ErrnoException`\n\nOne of many different errors that occur when resolving (TypeScript type).\n\n###### Type\n\n```ts\ntype ErrnoExceptionFields = Error \u0026 {\n  errnode?: number | undefined\n  code?: string | undefined\n  path?: string | undefined\n  syscall?: string | undefined\n  url?: string | undefined\n}\n```\n\nThe `code` field on errors is one of the following strings:\n\n* `'ERR_INVALID_MODULE_SPECIFIER'`\n  — when `specifier` is invalid (example: `'#'`)\n* `'ERR_INVALID_PACKAGE_CONFIG'`\n  — when a `package.json` is invalid (example: invalid JSON)\n* `'ERR_INVALID_PACKAGE_TARGET'`\n  — when a `package.json` `exports` or `imports` is invalid (example: when it\n  does not start with `'./'`)\n* `'ERR_MODULE_NOT_FOUND'`\n  — when `specifier` cannot be found in `parent` (example: `'some-missing-package'`)\n* `'ERR_NETWORK_IMPORT_DISALLOWED'`\n  — thrown when trying to resolve a local file or builtin from a remote file\n  (`node:fs` relative to `'https://example.com'`)\n* `'ERR_PACKAGE_IMPORT_NOT_DEFINED'`\n  — when a local import is not defined in an import map (example: `'#local'`\n  when not defined)\n* `'ERR_PACKAGE_PATH_NOT_EXPORTED'`\n  — when an export is not defined in an export map (example: `'tape/index.js'`,\n  which is not in its export map)\n* `'ERR_UNSUPPORTED_DIR_IMPORT'`\n  — when attempting to import a directory (example: `'./lib/'`)\n* `'ERR_UNKNOWN_FILE_EXTENSION'`\n  — when somehow reading a file that has an unexpected extensions (`'./readme.md'`)\n* `'ERR_INVALID_ARG_VALUE'`\n  — when `conditions` is incorrect\n\n## Algorithm\n\nThe algorithm for `resolve` matches how Node handles `import.meta.resolve`, with\na couple of differences.\n\nThe algorithm for `moduleResolve` matches the [Resolver Algorithm\nSpecification][algo] as detailed in the Node docs (which is sync and slightly\nlower-level than `resolve`).\n\n## Differences to Node\n\n* `parent` defaulting to `import.meta.url` cannot be ponyfilled: you have to\n  explicitly pass it\n* no support for loaders (that would mean implementing all of loaders)\n* no support for CLI flags:\n  `--conditions`,\n  `--experimental-default-type`,\n  `--experimental-json-modules`,\n  `--experimental-network-imports`,\n  `--experimental-policy`,\n  `--experimental-wasm-modules`,\n  `--input-type`,\n  `--no-addons`,\n  `--preserve-symlinks`, nor\n  `--preserve-symlinks-main`\n  work\n* no support for `WATCH_REPORT_DEPENDENCIES` env variable\n* no attempt is made to add a suggestion based on how things used to work in\n  CJS before to not-found errors\n* prototypal methods are not guarded: Node protects for example `String#slice`\n  or so from being tampered with, whereas this doesn’t\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`ErrnoException`][errnoexception].\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 16 and later.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author] and Node.js contributors\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/wooorm/import-meta-resolve/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/import-meta-resolve/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/import-meta-resolve.svg\n\n[coverage]: https://codecov.io/github/wooorm/import-meta-resolve\n\n[downloads-badge]: https://img.shields.io/npm/dm/import-meta-resolve.svg\n\n[downloads]: https://www.npmjs.com/package/import-meta-resolve\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[algo]: https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_resolver_algorithm\n\n[native-resolve]: https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent\n\n[resolve]: #resolvespecifier-parent\n\n[moduleresolve]: #moduleResolvespecifier-parent-conditions-preserveSymlinks\n\n[errnoexception]: #errnoexception\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fimport-meta-resolve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fimport-meta-resolve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fimport-meta-resolve/lists"}