dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.82k stars 104 forks source link

loadConfig(configFile) not working #162

Open dl748 opened 3 years ago

dl748 commented 3 years ago

tsconfig-path's seems to be overriding the option if a TS_NODE_PROJECT file is set. Environment variables should only be use if there is no option specifying them.

Workflow I have is this.

I have webpack.config.ts that needs to be compiled for ts-node so I have a specific file for typescript to compile for running as node, set with TS_NODE_PROJECT. But I then I have a tsconfig.json file that is for webpack for compiling a web application (non-node) The problem I've traced to is that even those configFile is set, tsconfig-paths is overriding it with a environment variable. Options passed in should always take precedence.

This is due to these sections of code

https://github.com/dividab/tsconfig-paths/blob/1fec36dfc685958d56400d9b5575efc4d5be549b/src/tsconfig-loader.ts#L37-L41

and

https://github.com/dividab/tsconfig-paths/blob/1fec36dfc685958d56400d9b5575efc4d5be549b/src/tsconfig-loader.ts#L66-L72

In my setup, I have an absolute path to a tsconfig.json file

/myprojects/mainproject/tsconfig.build.json is the cwd but TS_NODE_PROJECT is blowing that away.

More detail, tsconfig-paths-webpack-plugin calls loadConfig('/mypath/tsconfig.json') // loadFrom = /mypath/tsconfig.json

but its loading '/mytsnode/tsconfig.json'

https://github.com/dividab/tsconfig-paths-webpack-plugin/blob/988a5c70ac2ad68c576af8be722cfc848f32eabb/src/plugin.ts#L146-L148