Skip to content

Cannot resolve #/ subpath imports (blocked by import-meta-resolve) #1

Description

@dfyz011

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

// package.json
{ "type": "module", "imports": { "#/*": "./src/*" } }
// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions