evanw / evanw/esbuild

tsconfig `paths` are not transformed if not bundling

Open
#394 21 comments 74 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
40.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

```console
$ cat tsconfig.json
{
"compilerOptions": {
# ...
"paths": {
"lib/*": ["lib/*"]
}
},
}

$ echo "import logger from 'lib/logger'" | esbuild --format=cjs
# ...
const logger = __toModule(require("lib/logger"));
```

^ the import/require is left as-is (as opposed to being transformed to `./lib/logger`), so will fail if run, say in Node.js

Was thinking about whether it's esbuild's responsibility to do the transform, and I feel it is: as a ts-to-js transformer, it should perform any transforms implied in tsconfig.json, including path transforms

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the tsconfig.json example and reproduce the esbuild --format=cjs command using the paths setting. Check how the import is emitted when bundling is disabled and compare that with the expected ./lib/logger resolution in Node.js. Done means the configured path alias is transformed correctly or the behavior is clearly documented as unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.