S
S
Svyatoslav Khusamov2017-03-29 09:53:50
Node.js
Svyatoslav Khusamov, 2017-03-29 09:53:50

How to make Typescript compiler recalculate paths relative to baseUrl in JS output code?

To avoid long import paths, I use the `baseUrl` typescript parameter in my `tsconfig.json`:

{
        "compilerOptions": {
            ...
            "baseUrl": "./"
        },
        ...
    }

Next, instead of this import: I write the following: This works in the TypeScript compiler, but when I run my application with `node.js` I get an error:
import foo from "../../../../hello/foo"
import foo from "hello/foo"
module.js:474
        throw err;
        ^
    
    Error: Cannot find module 'hello/foo'

I don't want to change the `require()` function, this kind of solution has been suggested a lot on the internet.
Summary:
How to get `node.js` to work with `baseUrl` or, more preferably, how to get the TypeScript compiler to change paths from `"hello/foo"` to `"../../../../hello/ foo"` in the output js code.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question