question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Absolute base url calculated relative to running code, not tsconfig path

See original GitHub issue

I have this app structure

tsconfig.json
shared/
services/
  service1/
    index.js

with

const tsConfig = require('../../tsconfig.json');
const tsConfigPaths = require('tsconfig-paths');

tsConfigPaths.register({
  baseUrl: tsConfig.compilerOptions.baseUrl,
  paths: tsConfig.compilerOptions.paths
});

inside index.js tsconfig basUrl configured as

    "baseUrl": "./services/",
    "shared/*": [ "../shared/*" ]

to allow imports like import {} from 'service1/smth'

but tsconfig-paths makes wrong absolute path for this baseUrl

configLoaderResult { resultType: 'success',
  absoluteBaseUrl: '.../services/service1/services/',

instead of just .../services/

https://github.com/jonaskello/tsconfig-paths/blob/master/src/config-loader.ts#L35

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Jontemcommented, May 23, 2017

I’ve made an implementation of this in the commit https://github.com/jonaskello/tsconfig-paths/commit/cb18815b80374a6c071061bb8d92fc52b35c69e0

I have just quickly tested it and it seems to work. I’ll release it when i have more time to verify. But please try it out.

1reaction
Jontemcommented, May 26, 2017

Fixed in 2.2.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Absolute path in the tsconfig doesn't work - node.js
Update the tsconfig.json file with the following options: ... of entries which re-map imports to lookup locations relative to the 'baseUrl'.
Read more >
Documentation - Module Resolution - TypeScript
value of baseUrl property in 'tsconfig.json' (if given path is relative, it is computed based on the location of 'tsconfig.json'). Note that relative...
Read more >
tsconfig-paths - npm
Either absolute or relative path. If relative it's resolved to current working directory. const cleanup = tsConfigPaths.register({ baseUrl, ...
Read more >
Typescript: How to auto import with absolute paths if baseUrl ...
In my tsconfig.json I have set a base url: "baseUrl": "src/app", ... WebStorm calculates import paths relative to "baseUrl" specified in ...
Read more >
Typescript paths with ts-node, ts-node-dev and Jest | Medium
To achieve the non-relative import mentioned above, tsconfig.json could look like this: From the TypeScript docs: baseUrl: Specify the base ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found