can1357/oh-my-pi · error · Error

Package import "${specifier}" is excluded by its package imp

Error message

Package import "${specifier}" is excluded by its package imports map

What it means

When resolving TS `paths`-style package `imports` entries (the `#foo` subpath imports of a package.json `imports` map), a resolution can be the sentinel PACKAGE_IMPORT_EXCLUDED when the imports map explicitly excludes the specifier (e.g. null target). packageImportPath converts the sentinel into a thrown error, so callers never treat exclusion as a valid path.

Source

Thrown at packages/coding-agent/src/extensibility/plugins/legacy-pi-compat.ts:1495

		}

		if (!bestMatch || key.length > bestMatch.keyLength) {
			bestMatch = {
				keyLength: key.length,
				target,
				wildcard: specifier.slice(prefix.length, specifier.length - suffix.length),
			};
		}
	}

	if (!bestMatch || bestMatch.target === PACKAGE_IMPORT_EXCLUDED) {
		return bestMatch?.target ?? null;
	}
	return resolvePackageImportTarget(packageRoot, bestMatch.target, bestMatch.wildcard);
}
function packageImportPath(specifier: string, resolution: PackageImportResolution): string | null {
	if (resolution === PACKAGE_IMPORT_EXCLUDED) {
		throw new Error(`Package import "${specifier}" is excluded by its package imports map`);
	}
	return resolution;
}

function isBareExtensionDependencySpecifier(specifier: string): boolean {
	if (
		specifier.startsWith(".") ||
		specifier.startsWith("/") ||
		specifier.startsWith("#") ||
		specifier.startsWith("node:") ||
		specifier.startsWith("bun:") ||
		/^[a-z][a-z0-9+.-]*:/i.test(specifier)
	) {
		return false;
	}
	const packageName = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0];
	return Boolean(packageName && !isBuiltin(specifier));
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Remove the null/excluding entry from the package.json `imports` map or point it at a real target
  2. Import the underlying file directly instead of the excluded `#specifier`
  3. Use a different subpath key that maps to an actual target
  4. Check the conditions/patterns in the imports map match how the specifier is written

Example fix

// before: package.json
{ "imports": { "#config": null } }
// after
{ "imports": { "#config": "./config.ts" } }
Defensive patterns

Strategy: try-catch

Validate before calling

const pkgJson = JSON.parse(await Bun.file(packageRoot + "/package.json").text());
const entry = pkgJson.imports?.["#my-specifier"];
if (entry === null || entry === undefined) {
	throw new Error(`#my-specifier is excluded or absent in imports map`);
}

Try / catch

try {
	const p = packageImportPath(spec, resolution);
} catch (err) {
	if (err instanceof Error && err.message.includes("excluded by its package imports map")) {
		// fall back to direct relative import or fix the imports map
	}
	throw err;
}

Prevention

When it happens

Trigger: An extension's code imports a `#specifier` whose package.json `imports` map has a null/excluding entry for the best match, and the compat layer attempts to resolve it to a file path.

Common situations: Extension authors used `"imports": { "#x": null }` to deliberately block a subpath; a copied imports map from another tool where exclusion semantics differ; resolving internal `#` imports of a dependency whose map excludes the requested condition.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/0e4f3f4f3b5375ac. Report an issue: GitHub.