Skip to content

Commit a214720

Browse files
authored
fix(rest): Use namespace import for path-to-regexp CJS interop (#3862)
Switch from named imports to `import *` for the CJS path-to-regexp dependency. Named imports trigger webpack's per-export presence validation (`importExportsPresence`), which fails in StackBlitz WebContainers. Namespace imports defer property access to runtime, bypassing the check with no tree-shaking loss. Made-with: Cursor
1 parent 17d938b commit a214720

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@data-client/rest': patch
3+
---
4+
5+
Fix StackBlitz WebContainers compatibility with path-to-regexp
6+
7+
Use namespace import (`import *`) instead of named imports for the CJS
8+
`path-to-regexp` dependency. Named imports trigger webpack's per-export
9+
presence validation, which fails in StackBlitz's WebContainers environment.
10+
Namespace imports defer property access to runtime, bypassing the check
11+
with no tree-shaking loss.

packages/rest/src/RestHelpers.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {
2-
compile,
3-
PathFunction,
4-
parse,
5-
pathToRegexp,
6-
Token,
7-
ParamData,
8-
} from 'path-to-regexp';
1+
// Namespace import avoids webpack's per-export CJS validation, which fails in
2+
// StackBlitz WebContainers. Named imports (`import { compile }`) trigger
3+
// `importExportsPresence` checks that break there. `import *` defers property
4+
// access to runtime. No tree-shaking loss: CJS modules are included whole
5+
// regardless of import style, and webpack 5 traces static access on namespaces.
6+
import type { PathFunction, Token, ParamData } from 'path-to-regexp';
7+
import * as pathToRegexpModule from 'path-to-regexp';
8+
const { compile, parse, pathToRegexp } = pathToRegexpModule;
99

1010
import { ShortenPath } from './pathTypes.js';
1111

0 commit comments

Comments
 (0)