tsconfig-paths-webpack-plugin icon indicating copy to clipboard operation
tsconfig-paths-webpack-plugin copied to clipboard

Unexpected error with webpack + ts-node + TS_NODE_PROJECT

Open jupl opened this issue 6 years ago • 3 comments

Scenario 1:

  • Using webpack.config.js
  • tsconfig.json extends from tsconfig.base.json
  • tsconfig.base.json has baseUrl and paths
  • Executing webpack works fine with plugin

Scenario 2:

  • Using webpack.config.ts (ts-node is installed)
  • tsconfig.json extends from tsconfig.base.json
  • tsconfig.base.json has baseUrl and paths
  • Executing webpack works fine with plugin

Scenario 3:

  • Using webpack.config.ts (ts-node is installed)
  • tsconfig.json extends from tsconfig.base.json
  • tsconfig.base.json has baseUrl and paths
  • Executing TS_NODE_PROJECT=tsconfig.base.json webpack complains that missing baseUrl in compilerOptions

In all scenarios if within webpack.config I run below I get success so scenario 3 should work fine:

const TsconfigPaths = require('tsconfig-paths')
console.log(TsconfigPaths.loadConfig().resultType)

jupl avatar Nov 27 '18 14:11 jupl

Did you try adding process.env['TS_NODE_PROJECT'] = ''; to webpack.config.ts?

Why you guys down vote a workaround? I am not the author of the library anyway. 🤷‍♂

vilicvane avatar Dec 16 '18 16:12 vilicvane

...

🤦‍♂️

That. Makes. Sense.

Thanks! Going to leave this open for now to see if this should be a proper solution.

jupl avatar Dec 16 '18 17:12 jupl

@jonaskello I've faced the same issue right now. Although workaround with setting the env variable inside script works fine, it would be much better to fix this inside the library itself, IMHO.
My main reason is that configFile has file in its name and situations when TS_NODE_PROJECT is set and configFile param is being used like base path are creating some really strange behavior.
I would suggest replacing configFile with multiple params. One of those will behave like the current one and another one will always be treated as a path to file.

ghost avatar Sep 12 '19 15:09 ghost