TypeScript Compiler Options
resolvePackageJsonImports — TypeScript compiler option
Controls lookup of # specifiers through the nearest package imports map in supported modes. This is package-private resolution; does not change runtime rules. Default (5.8.3): true for Node16, NodeNext and Bundler; otherwise false. Create the labeled files in an isolated local project and run tsc -p tsconfig.json. Expected: no diagnostics; emitted files: none. Local multi-file fixture, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "resolvePackageJsonImports": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| resolvePackageJsonImports | boolean | Set in compilerOptions; default: true for Node16, NodeNext and Bundler; otherwise false. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "ESNext", "strict": true, "types": [], "noEmitOnError": true, "noEmit": true, "moduleResolution": "Bundler", "resolvePackageJsonImports": true }, "files": [ "main.ts" ]}// File: main.tsimport { value } from "#local"; const checked: number = value;// File: package.json{ "imports": { "#local": "./value.d.ts" }}// File: value.d.tsexport declare const value: number;