Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc3ac46

Browse files
authored
fix: use import default esm helper for esm path imports (#1302)
1 parent3992894 commitbc3ac46

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

‎.changeset/brown-pillows-write.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack":patch
3+
---
4+
5+
Fix`ERR_UNSUPPORTED_ESM_URL_SCHEME` errors when bundling on Windows

‎packages/repack/src/commands/common/config/getMinimizerConfig.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
importsemverfrom'semver';
2+
importtypeTerserPluginfrom'terser-webpack-plugin';
3+
import{importDefaultESM}from'../../../helpers/index.js';
24

35
// prefer `terser-webpack-plugin` installed in the project root to the one shipped with Re.Pack
46
asyncfunctiongetTerserPlugin(rootDir:string){
@@ -10,8 +12,8 @@ async function getTerserPlugin(rootDir: string) {
1012
}catch{
1113
terserPluginPath=require.resolve('terser-webpack-plugin');
1214
}
13-
constplugin=awaitimport(terserPluginPath);
14-
return'default'inplugin ?plugin.default :plugin;
15+
constplugin=awaitimportDefaultESM<typeofTerserPlugin>(terserPluginPath);
16+
returnplugin;
1517
}
1618

1719
asyncfunctiongetTerserConfig(rootDir:string){

‎packages/repack/src/commands/common/getDevMiddleware.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
importurlfrom'node:url';
2+
13
exportasyncfunctiongetDevMiddleware(reactNativePath:string){
24
constreactNativeCommunityCliPluginPath=require.resolve(
35
'@react-native/community-cli-plugin',
@@ -8,5 +10,7 @@ export async function getDevMiddleware(reactNativePath: string) {
810
paths:[reactNativeCommunityCliPluginPath],
911
});
1012

11-
returnimport(devMiddlewarePath);
13+
// use fileURL to import correctly on both Windows & MacOS
14+
const{href:fileUrl}=url.pathToFileURL(devMiddlewarePath);
15+
returnawaitimport(fileUrl);
1216
}

‎packages/repack/src/helpers/helpers.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importosfrom'node:os';
2+
importurlfrom'node:url';
23
importtype{CompilerasRspackCompiler}from'@rspack/core';
34
importtype{CompilerasWebpackCompiler}from'webpack';
45

@@ -60,3 +61,9 @@ export function moveElementBefore<T>(
6061
// Insert source element right before the target element
6162
array.splice(targetIndex,0,moveElement);
6263
}
64+
65+
exportasyncfunctionimportDefaultESM<T>(absolutePath:string):Promise<T>{
66+
const{href:fileUrl}=url.pathToFileURL(absolutePath);
67+
constmodule=awaitimport(fileUrl);
68+
return'default'inmodule ?module.default :module;
69+
}

‎packages/repack/src/loaders/babelLoader/utils.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importtype{ParseResult}from'@babel/core';
2+
import{importDefaultESM}from'../../helpers/index.js';
23

34
interfaceHermesParser{
45
parse:(
@@ -46,7 +47,7 @@ export async function loadHermesParser(
4647
consthermesParserPath=
4748
providedHermesParserPath??
4849
resolveHermesParser(projectRoot??process.cwd());
49-
consthermesParser=awaitimport(hermesParserPath);
50+
consthermesParser=awaitimportDefaultESM<HermesParser>(hermesParserPath);
5051
returnhermesParser;
5152
}catch(e){
5253
console.error(e);

‎packages/repack/src/loaders/babelSwcLoader/utils.ts‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {
44
SwcLoaderParserConfig,
55
experiments,
66
}from'@rspack/core';
7+
importtypeRspackfrom'@rspack/core';
8+
import{importDefaultESM}from'../../helpers/index.js';
79

810
typeSwc=(typeofexperiments)['swc'];
911
typeLogger=ReturnType<LoaderContext['getLogger']>;
@@ -136,26 +138,16 @@ async function getSwcModule(loaderContext: LoaderContext): Promise<Swc | null> {
136138
// use optional chaining to avoid type errors when there is no experiments.swc
137139
constrspackCorePath=safelyResolve('@rspack/core',projectRoot);
138140
if(rspackCorePath&&!isWebpack){
139-
constrspack=awaitimport(rspackCorePath);
140-
if('default'inrspack){
141-
returnrspack.default?.experiments?.swc??null;
142-
}
143-
if(rspack){
144-
returnrspack?.experiments?.swc??null;
145-
}
141+
constrspack=awaitimportDefaultESM<typeofRspack>(rspackCorePath);
142+
returnrspack.experiments?.swc??null;
146143
}
147144
}
148145
// fallback to checking for `@swc/core` installed in the project
149146
// this can be in both webpack & rspack projects
150147
constswcCorePath=safelyResolve('@swc/core',projectRoot);
151148
if(swcCorePath){
152-
constswc=awaitimport(swcCorePath);
153-
if('default'inswc){
154-
returnswc.defaultasSwc;
155-
}
156-
if(swc){
157-
returnswcasSwc;
158-
}
149+
constswc=awaitimportDefaultESM<Swc>(swcCorePath);
150+
returnswc;
159151
}
160152
// at this point, we've tried all possible ways to get swc and failed
161153
returnnull;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp