Inferring absolute path from compilerOptions paths

40 views Asked by At

I'm using compilerOptions: paths together with tsconfig-paths

$ cat tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": { "@folder1/*": ["utils/*"] },
    "module": "commonjs"
  }
}

Here is the simple example I use

import 'tsconfig-paths/register';
import { myLovelyUtilsFunction } from "@folder1/myUtils"
const y = myLovelyUtilsFunction();
console.log(`>>> ${y}`);

Transpiling and running goes fine:

$ npx tsc -p tsconfig.json
$ node src/main.js        
### expected output ...

I want to resolve the absolute path locations at transpilation time, docs:

If you require this package's tsconfig-paths/register module it will read the paths from tsconfig.json or jsconfig.json and convert node's module loading calls into to physical file paths that node can load

But when I look at the generated javascript file I see the load will be done on runtime:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("tsconfig-paths/register");
var myUtils_1 = require("@folder1/myUtils"); // <--- why not resolve it ?
var y = (0, myUtils_1.myLovelyUtilsFunction)();
console.log(">>> ".concat(y));
0

There are 0 answers