Jeppe Stougaard
Jeppe Stougaard

Reputation: 422

What is the root of an absolute path when importing a module in typescript?

I'm developing an app in typescript (in Visual Studio 2015) and have this basic file structure:

Solution
    AppProject
        Scripts
            framework
                Utils.ts
            app
                SomeApp.ts
        tsconfig.json

Now within the app modules, I would like to reference the framework modules with an absolute path, so I would do something like this:

import { Utils } from '/Scripts/framework/Utils'

However this doesn't work.
I'm getting the red squiggly line and a "Cannot find module '/Scripts/framework/Utils'"

I works fine when doing a relative path, but the app is obviously more complex than what is shown, and I don't want to deal with stepping out multiple levels for my relative path.

I am using typescript 1.8 with the node module resolution strategy.
And webpack to compile and bundle it, if that matters

Upvotes: 7

Views: 2749

Answers (1)

raphinesse
raphinesse

Reputation: 20998

Unfortunately I couldn't find anything on that in the docs. So I traced the file system accesses performed by the compiler (TypeScript 2.5.2) when trying to resolve an import of an absolute path.

The result is that / always refers to the file system root. Regardless of compilerOptions like rootDir, rootDirs or baseUrl.

Upvotes: 7

Related Questions