@ai-sdk/provider-utils 4.0.41 → 4.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "4.0.41",
3
+ "version": "4.0.43",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -140,9 +140,8 @@ function isNodeDefaultFetch(fetch: FetchFunction): boolean {
140
140
  }
141
141
 
142
142
  async function createSafeNodeFetch(): Promise<FetchFunction> {
143
- // Node 20.16+ exposes getBuiltinModule; older supported Node versions use an
144
- // indirect dynamic import. Keeping the specifier non-literal prevents browser
145
- // bundlers from pulling Node built-ins into the provider-utils entry point.
143
+ // Load Node-only modules indirectly so browser bundlers do not pull undici
144
+ // and Node built-ins into the browser-facing provider-utils entry point.
146
145
  const [{ createRequire }, { lookup }] = await Promise.all([
147
146
  loadNodeModule<NodeModule>('node:module'),
148
147
  loadNodeModule<NodeDns>('node:dns'),
@@ -175,13 +174,16 @@ async function loadNodeModule<T>(id: string): Promise<T> {
175
174
  | undefined;
176
175
  const builtinModule = processWithBuiltins?.getBuiltinModule?.(id);
177
176
 
178
- return builtinModule == null
179
- ? ((await importNodeModule(id)) as T)
180
- : (builtinModule as T);
181
- }
177
+ if (builtinModule == null) {
178
+ // There is no bundle-safe way to load Node built-ins without
179
+ // process.getBuiltinModule (Node <20.16): Metro rejects non-static
180
+ // import() expressions while parsing, and Next.js Edge Runtime rejects
181
+ // the Function-constructor shim during static analysis. Throw rather
182
+ // than ship either, matching the v7 implementation. See #18545, #18559.
183
+ throw new Error(`Node.js built-in module ${id} is unavailable`);
184
+ }
182
185
 
183
- function importNodeModule(id: string): Promise<unknown> {
184
- return import(id);
186
+ return builtinModule as T;
185
187
  }
186
188
 
187
189
  function getCurrentModulePath(): string {