tsconfig-paths-webpack-plugin
tsconfig-paths-webpack-plugin copied to clipboard
Support TypeScript 4.1
TypeScript 4.1 adds an option to use path mapping without specifying baseUrl
, more about it in TypeScript 4.1 Release Notes
My project is using TypeScript 4.1.2, trying to remove the baseUrl
I get the following error
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
Would like to submit a PR with a little help :)
See also: dividab/tsconfig-paths#143, https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/32#issuecomment-695134747
Since 4.1, I've worked around this with secondary configs that extend and add a baseUrl; after hitting more bugs like #60, I've found that it's easier to drop the plugin in favor of a little code that transforms the paths config into webpack resolve aliases; the output is identical to the tsconfig-paths plugin (when it's working).
@jakebailey
Hi, share please your solution / example repo? I have similar issues
Sure, the function I wrote to generate aliases is here: https://github.com/microsoft/pyright/blob/169c6089b9914870c43622743c75844657cd9d70/build/lib/webpack.js#L90
resolve.alias
gets set to the return value of this function.
As far as I can tell, this is all you need to support tsconfig paths. It verifies enough to make the file ts-check
(hence the asserts), but otherwise is all that's really needed to make paths work, no plugin needed.
https://github.com/microsoft/pyright/blob/169c6089b9914870c43622743c75844657cd9d70/build/lib/webpack.js#L90
resolve: {
extensions: ['.ts', '.js'],
alias: tsconfigResolveAliases('tsconfig.json'),
},
That is enough?
Correct.
Correct.
With storybook it is correct usage?
webpackFinal: async (config) => {
// resolve problem with typescript aliases
config.resolve.alias = {
...config.resolve?.alias,
...tsconfigResolveAliases('../tsconfig.json'),
};
....
}
I have no idea what storybook is, but I don't see why not. Can't hurt to try.
I have no idea what storybook is, but I don't see why not. Can't hurt to try.
I have that config
{
"extends": "./tsconfig/nextjs.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}
With JSONC
you parse content of file and compilerOptions
required inside.
Any workaround for that kind of configs?
filepath on the field extends
may have similar extends
(That is how monorepo configs structured)
Last I looked, paths
is not a config that is carried over from the extended config, so if your project doesn't copy/paste paths
around, they aren't working correctly in the first place, and my snippet is still doing the right thing by not following extended paths. The project that uses my little helper (pyright and Pylance) are forced to duplicate them in every tsconfig.