3 ms·
> There's no way to remap a "global package identifier" to the entry point (e.g. remap import from "package" to "../path/to/mymodules/package/index.mjs") on the
by timdaub 6y ago
> There's no way to remap a "global package identifier" to the entry point (e.g. remap import from "package" to "../path/to/mymodules/package/index.mjs") on the Browser-side.
I think what you're looking for is `require.resolve` [1].
```mjs
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const path = require.resolve("package");
console.log(path);
>> ../path/to/mymodules/package/index.mjs
```
1: https://nodejs.org/api/esm.html#esm_no_require_resolve https://nodejs.org/api/esm.html#esm_no_require_resolve
- cookiengineer 6y agoI was talking about Browser-side, the cleaner node.js solution is to use the "exports{}" map in the package.json [1] that I mentioned before. Personally, I wouldn't recommend to override the require.resolve or import.meta.resolve algorithm, as this is heavily experimental. [1] https://nodejs.org/api/packages.html#packages_exports https://nodejs.org/api/packages.html#packages_exports