tsconfig-paths crashes when `compilerOptions` is not present
See original GitHub issueTo reproduce:
tsconfig.json:
{
"extends": "../../tsconfig.json",
}
Now I run: "test": "mocha --no-timeouts --compilers ts:ts-node/register -r tsconfig-paths/register 'tests/index.ts'"
And get:
/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/lib/tsconfig-loader.js:17
baseUrl: loadResult.config.compilerOptions.baseUrl,
^
TypeError: Cannot read property 'baseUrl' of undefined
at loadSyncDefault (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/lib/tsconfig-loader.js:17:51)
at tsConfigLoader (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/lib/tsconfig-loader.js:8:22)
at Object.configLoader (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/lib/config-loader.js:18:22)
at Object.register (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/lib/register.js:9:46)
at Object.<anonymous> (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/tsconfig-paths/register.js:1:15)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at /home/whoeverest/freelance/99abcproj/my-work-project/node_modules/mocha/bin/_mocha:345:3
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/whoeverest/freelance/99abcproj/my-work-project/node_modules/mocha/bin/_mocha:344:10)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Function.Module.runMain (module.js:609:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:598:3
If I add compilerOptions
to tsconfig.json
it works. This doesn’t crash:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./build"
}
}
Then I get a warning: Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
I’m not very familiar with this tool, but it’s obvious that it tries to read from compilerOptions
which in this case is undefined
. Hope it makes sense.
EDIT: BTW, there is a baseUrl
defined in the top-level tsconfig.json
which the local one extends. Is that a bug, too?
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Test tsconfig, losing autocompletion and typing when ...
Short answer: Add "baseUrl": "." to your tests/tsconfig.json . Explanation: The tests/tsconfig.json inherits the baseUrl from the main ...
Read more >TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
Read more >tsconfig-paths
The typescript compiler can resolve these paths from tsconfig so it will compile OK. But if you then try to execute the compiled...
Read more >Typescript — How to solve the problem with unresolved ...
js file containing the line with the path alias. The actual cause of the issue is that the tsc compiler does not transpiles...
Read more >Typescript: "paths" tsconfig - YouTube
# typescript # tsc Here's a thing that might help you with staying focused on features by setting a perman … Show more....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, we are using the tsconfig package to read the tsconfig.json file. The tsconfig.json file is not 100% json. For example it allows for comments which the json standard does not. I think submitting a PR for the issue mentioned above would be the best solution.
I have set
paths
andbaseUrl
in the maintsconfig.json
from which I extend:I think some part of the library code parses the derived
tsconfig.json
, assumes thatcompilerOptions
is present on the object (when trying to check if baseUrl is present) and throws the exception “Cannot read property ‘baseUrl’ of undefined”.A totally blind guess: some check somewhere needs to look like this:
obj.compilerOptions && obj.compilerOptions.baseUrl
😃