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.

Bug with extends property in tsconfig

See original GitHub issue

Issue

Right now, when I use a tsconfig file that extends another config file, the paths defined in the base config file are not recognized by tsconfig-paths-webpack-plugin. Sample config files:

// tsconfig.browser.json
{
    "compilerOptions": {
        ...
        "baseUrl": "../",
        "paths": {
            "@injector/*": ["src/browser/injector/*"],
            "@records/*": ["src/browser/records/*"],
            "@services/*": ["src/browser/services/*"],
            "@shared-components/*": ["src/browser/shared-components/*"],
            "@signals/*": ["src/browser/signals/*"],
            "*": [
                "*",
                "src/browser/@types/*"
            ]
        }
    },
    "include": [
        "../src/browser/**/*"
    ],
    "exclude": [
        "../src/electron/**/*"
    ]
}
// tsconfig.test
{
    "extends": "./tsconfig.browser",
    "compilerOptions": {
        "outDir": "../build-test",
        "types": ["reflect-metadata", "webpack-env", "mocha"]
    }
}

Output when using tsconfig-paths-webpack-plugin: Failed to load tsconfig.json: Missing baseUrl in compilerOptions tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin

Expected behavior

tsconfig-paths-webpack-plugin should read the extends property to build the compiler options object so it can properly determine the proper values for baseUrl and paths in projects that utilize the extends propert in their config files. See more detailed description here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html.

Possible solution

I think this is a bug with the loadTsConfig method in tsconfig-loader.ts. It’s assuming that config files mentioned in the extends property will include a .json file extension. However, that extension isn’t required by typescript. My suggestion would be to add .json to the end of any string found in the extends property that doesn’t already end in .json.

EDIT: It looks like the guys who maintain tsconfig are working on the extends property right now (see https://github.com/TypeStrong/tsconfig/issues/21). It might be easier to bring in their project so you don’t have to do the tsconfig file parsing yourself.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lostfictionscommented, May 8, 2018

Just bumped into this issue. It doesn’t seem to be a missing .json suffix in my case – my extends clause reads "extends": "../tsconfig.base.json", but I still get Failed to load tsconfig.json: Missing baseUrl in compilerOptions tsconfig-paths-webpack-plugin: Found no baseUrl in tsconfig.json, not applying tsconfig-paths-webpack-plugin

0reactions
jonaskellocommented, May 8, 2018

@lostfictions If you could setup a sample repo that demonstrates the problem that would be very helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
The value of extends is a string which contains a path to another configuration file to ... Properties with relative paths found in...
Read more >
Property in type is not assignable to the same property in base ...
Typescript complains because somehow the type of the abstract property is lost when extending. Is this a bug or am I doing something...
Read more >
TypeScript errors and how to fix them
Set the “target” property in your “tsconfig.json” file to “es5” or higher: ... export interface SerializedBatchedCandle extends Omit<BatchedCandle, 'close', ...
Read more >
"extends" in tsconfig.json is not treated like a path - YouTrack
The extends property in tsconfig.json should be a file path, but WebStorm treats it as a string, offering no autocompletion or file linking...
Read more >
Using TypeScript - Expo Documentation
A project's tsconfig.json should extend the expo/tsconfig.base by default. ... For more information on the available properties see the TypeScript compiler ...
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