How to get tsc to Resolve Absolute Paths when Importing Modules using baseUrl?

The answer comes from @DenisPshenov's comment in one of the answers. It's buried, so I'll provide it here...

Tell Node where the base url is with NODE_PATH environment variable so that it can resolve absolute paths:

Linux / macOS

NODE_PATH=dist/ node ./dist/index.js

Windows Powershell

$env:NODE_PATH="dist/"
node ./dist/index.js

The problem is that your module loader does not know how to find the module given the absolute path foobar/Foo.

The TypeScript compiler (tsc) is resolving the module paths correctly, otherwise you would get compilation errors. But it is trusting you to configure your module loader appropriately.

For example, from the documentation for RequireJS:

Supported configuration options:

baseUrl: the root path to use for all module lookups.

The TypeScript documentation talks a little about why you might need baseUrl:

Using a baseUrl is a common practice in applications using AMD module loaders where modules are “deployed” to a single folder at run-time. The sources of these modules can live in different directories, but a build script will put them all together.