Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/fix-stackblitz-cjs-interop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@data-client/rest': patch
---

Fix StackBlitz WebContainers compatibility with path-to-regexp

Use namespace import (`import *`) instead of named imports for the CJS
`path-to-regexp` dependency. Named imports trigger webpack's per-export
presence validation, which fails in StackBlitz's WebContainers environment.
Namespace imports defer property access to runtime, bypassing the check
with no tree-shaking loss.
16 changes: 8 additions & 8 deletions packages/rest/src/RestHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
compile,
PathFunction,
parse,
pathToRegexp,
Token,
ParamData,
} from 'path-to-regexp';
// Namespace import avoids webpack's per-export CJS validation, which fails in
// StackBlitz WebContainers. Named imports (`import { compile }`) trigger
// `importExportsPresence` checks that break there. `import *` defers property
// access to runtime. No tree-shaking loss: CJS modules are included whole
// regardless of import style, and webpack 5 traces static access on namespaces.
import type { PathFunction, Token, ParamData } from 'path-to-regexp';
import * as pathToRegexpModule from 'path-to-regexp';
const { compile, parse, pathToRegexp } = pathToRegexpModule;

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

Expand Down
Loading