diff --git a/packages/rspack/src/executors/rspack/lib/config.ts b/packages/rspack/src/executors/rspack/lib/config.ts index 8e5f3154c28f7..4bd13653aff3b 100644 --- a/packages/rspack/src/executors/rspack/lib/config.ts +++ b/packages/rspack/src/executors/rspack/lib/config.ts @@ -1,4 +1,3 @@ -import { join } from 'path'; import { ExecutorContext } from '@nx/devkit'; import { type Configuration } from '@rspack/core'; import { @@ -14,7 +13,7 @@ export async function getRspackConfigs( options: NormalizedRspackExecutorSchema & { devServer?: any }, context: ExecutorContext ): Promise { - let userDefinedConfig = resolveUserDefinedRspackConfig( + let userDefinedConfig = await resolveUserDefinedRspackConfig( options.rspackConfig, options.tsConfig ); diff --git a/packages/rspack/src/plugins/plugin.ts b/packages/rspack/src/plugins/plugin.ts index 1e05fdaafeee2..f41acc61cbe94 100644 --- a/packages/rspack/src/plugins/plugin.ts +++ b/packages/rspack/src/plugins/plugin.ts @@ -124,7 +124,7 @@ async function createRspackTargets( ): Promise { const namedInputs = getNamedInputs(projectRoot, context); - const rspackConfig = resolveUserDefinedRspackConfig( + const rspackConfig = await resolveUserDefinedRspackConfig( join(context.workspaceRoot, configFilePath), getRootTsConfigPath(), true diff --git a/packages/rspack/src/utils/resolve-user-defined-rspack-config.ts b/packages/rspack/src/utils/resolve-user-defined-rspack-config.ts index 809a4b03c933d..8b7d4070f00a7 100644 --- a/packages/rspack/src/utils/resolve-user-defined-rspack-config.ts +++ b/packages/rspack/src/utils/resolve-user-defined-rspack-config.ts @@ -1,7 +1,7 @@ import { clearRequireCache } from '@nx/devkit/src/utils/config-utils'; import { registerTsProject } from '@nx/js/src/internal'; -export function resolveUserDefinedRspackConfig( +export async function resolveUserDefinedRspackConfig( path: string, tsConfig: string, /** Skip require cache and return latest content */ @@ -18,7 +18,7 @@ export function resolveUserDefinedRspackConfig( // Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths. // There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors. if (!/\.(ts|mts|cts)$/.test(path)) { - return import(path); + return await import(path); } const cleanupTranspiler = registerTsProject(tsConfig);