diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts b/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts index 4c49571e3cc80..bb8188bf19030 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/lib/apply-base-config.ts @@ -231,7 +231,9 @@ function applyNxDependentConfig( root: options.root, }; - plugins.push(new NxTsconfigPathsWebpackPlugin({ ...options, tsConfig })); + if (options.useTsconfigPaths) { + plugins.push(new NxTsconfigPathsWebpackPlugin({ ...options, tsConfig })); + } // New TS Solution already has a typecheck target if (!options?.skipTypeChecking && !isUsingTsSolutionSetup()) { diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/lib/normalize-options.ts b/packages/webpack/src/plugins/nx-webpack-plugin/lib/normalize-options.ts index 21c880be1e14b..9e9fdfbab2f88 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/lib/normalize-options.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/lib/normalize-options.ts @@ -12,6 +12,7 @@ import { NormalizedNxAppWebpackPluginOptions, NxAppWebpackPluginOptions, } from '../nx-app-webpack-plugin-options'; +import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; export function normalizeOptions( options: NxAppWebpackPluginOptions @@ -37,6 +38,8 @@ export function normalizeOptions( const projectNode = projectGraph.nodes[projectName]; const targetConfig = projectNode.data.targets[targetName]; + options.useTsconfigPaths = + options.useTsconfigPaths ?? !isUsingTsSolutionSetup(); normalizeRelativePaths(projectNode.data.root, options); diff --git a/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts b/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts index fac494d3ff5c6..cc6cac16aae06 100644 --- a/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts +++ b/packages/webpack/src/plugins/nx-webpack-plugin/nx-app-webpack-plugin-options.ts @@ -211,6 +211,10 @@ export interface NxAppWebpackPluginOptions { * List of TypeScript Compiler Transformers Plugins. */ transformers?: TransformerEntry[]; + /** + * Use tsconfig-paths-webpack-plugin to resolve modules using paths in the tsconfig file. + */ + useTsconfigPaths?: boolean; /** * Generate a separate vendor chunk for 3rd party packages. */