Summary
#/-prefixed subpath imports (e.g. import x from '#/foo' with "imports": { "#/*": "./src/*" } in package.json) fail to resolve and end up throwing Can't resolve import specifier "#/foo".
Root cause
resolve() delegates every attempt to moduleResolve from import-meta-resolve:
https://github.com/Poyoman39/specifier-resolution-node/blob/main/src/index.js#L3
For a #/… specifier, import-meta-resolve's packageImportsResolve throws ERR_INVALID_MODULE_SPECIFIER on its very first guard (name.startsWith('#/')), before any file lookup. So the direct attempt, the .js/.cjs/… extension attempts, and the index.* attempts all throw the same error, and the loader falls through to Can't resolve import specifier.
This mirrors an old Node restriction that has since been lifted:
Reproduction
// run with: node --import specifier-resolution-node/register ./src/main.js
import { thing } from '#/thing'; // → Error: Can't resolve import specifier "#/thing"
Blocked by
import-meta-resolve still enforces the #/ restriction regardless of Node version. Tracking upstream: wooorm/import-meta-resolve. Once that ships, bumping the import-meta-resolve dependency range here should be enough; until then #/ root aliases can't be used with this loader.
Environment
- specifier-resolution-node: 1.1.4
- import-meta-resolve: 4.2.0
- Node.js: 23.11.0
Summary
#/-prefixed subpath imports (e.g.import x from '#/foo'with"imports": { "#/*": "./src/*" }inpackage.json) fail to resolve and end up throwingCan't resolve import specifier "#/foo".Root cause
resolve()delegates every attempt tomoduleResolvefromimport-meta-resolve:https://github.com/Poyoman39/specifier-resolution-node/blob/main/src/index.js#L3
For a
#/…specifier,import-meta-resolve'spackageImportsResolvethrowsERR_INVALID_MODULE_SPECIFIERon its very first guard (name.startsWith('#/')), before any file lookup. So the direct attempt, the.js/.cjs/… extension attempts, and theindex.*attempts all throw the same error, and the loader falls through toCan't resolve import specifier.This mirrors an old Node restriction that has since been lifted:
#/nodejs/node#60864#/"): https://nodejs.org/docs/latest-v25.x/api/packages.html#subpath-importsReproduction
Blocked by
import-meta-resolvestill enforces the#/restriction regardless of Node version. Tracking upstream: wooorm/import-meta-resolve. Once that ships, bumping theimport-meta-resolvedependency range here should be enough; until then#/root aliases can't be used with this loader.Environment