docs: node does support "import path re-mapping" (#17133)

fixes #4545
This commit is contained in:
Michael H
2025-11-13 06:02:12 +11:00
committed by GitHub
parent 7f8dff64c4
commit fa099336da

View File

@@ -276,7 +276,7 @@ await Bun.build({
## Path re-mapping
In the spirit of treating TypeScript as a first-class citizen, the Bun runtime will re-map import paths according to the [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) field in `tsconfig.json`. This is a major divergence from Node.js, which doesn't support any form of import path re-mapping.
Bun supports import path re-mapping through TypeScript's [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) in `tsconfig.json`, which works well with editors. If you aren't a TypeScript user, you can achieve the same behavior by using a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root.
```json tsconfig.json icon="file-json"
{
@@ -289,7 +289,16 @@ In the spirit of treating TypeScript as a first-class citizen, the Bun runtime w
}
```
If you aren't a TypeScript user, you can create a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root to achieve the same behavior.
Bun also supports [Node.js-style subpath imports](https://nodejs.org/api/packages.html#subpath-imports) in `package.json`, where mapped paths must start with `#`. This approach doesnt work as well with editors, but both options can be used together.
```json package.json icon="file-json"
{
"imports": {
"#config": "./config.ts", // map specifier to file
"#components/*": "./components/*" // wildcard matching
}
}
```
<Accordion title="Low-level details of CommonJS interop in Bun">