Skip to content

Commit 37bca3f

Browse files
authored
fix: failed to use native config loader on Windows (#4512)
1 parent b10d4dc commit 37bca3f

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

e2e/cases/cli/config-loader/index.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { execSync } from 'node:child_process';
22
import path from 'node:path';
33
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
4-
import { expect, test } from '@playwright/test';
4+
import { expect } from '@playwright/test';
55

66
rspackOnlyTest('should use Node.js native loader to load config', async () => {
7-
// TODO: fix this test on Windows
8-
if (process.platform === 'win32') {
9-
test.skip();
10-
}
11-
127
execSync('npx rsbuild build --config-loader native', {
138
cwd: __dirname,
149
env: {

packages/core/src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs';
22
import { createRequire } from 'node:module';
33
import { dirname, isAbsolute, join } from 'node:path';
4+
import { pathToFileURL } from 'node:url';
45
import type { ChokidarOptions } from '../compiled/chokidar/index.js';
56
import RspackChain from '../compiled/rspack-chain/index.js';
67
import {
@@ -472,7 +473,8 @@ export async function loadConfig({
472473

473474
if (loader === 'native' || /\.(?:js|mjs|cjs)$/.test(configFilePath)) {
474475
try {
475-
const exportModule = await import(`${configFilePath}?t=${Date.now()}`);
476+
const configFileURL = pathToFileURL(configFilePath).href;
477+
const exportModule = await import(`${configFileURL}?t=${Date.now()}`);
476478
configExport = exportModule.default ? exportModule.default : exportModule;
477479
} catch (err) {
478480
if (loader === 'native') {

0 commit comments

Comments
 (0)