@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/CHANGELOG.md +12 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/safe-node-fetch.ts +11 -9
package/package.json
CHANGED
package/src/safe-node-fetch.ts
CHANGED
|
@@ -140,9 +140,8 @@ function isNodeDefaultFetch(fetch: FetchFunction): boolean {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
async function createSafeNodeFetch(): Promise<FetchFunction> {
|
|
143
|
-
// Node
|
|
144
|
-
//
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
184
|
-
return import(id);
|
|
186
|
+
return builtinModule as T;
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
function getCurrentModulePath(): string {
|