|
| 1 | +# Storage v7 to v8 Migration Guide - Node.js 18 & Gaxios Update |
| 2 | + |
| 3 | +This guide helps you migrate your application from `@google-cloud/storage` v7 to v8, focusing on the transition to Node.js 18+ as the minimum supported environment and changes introduced by updating the underlying HTTP client, `gaxios`, to version 7. |
| 4 | + |
| 5 | +## Minimum Requirements: Node.js 18 |
| 6 | + |
| 7 | +`@google-cloud/storage` v8 now officially requires Node.js 18 or higher. This update aligns the library with modern JavaScript environments and allows us to leverage standard native web APIs like the global `Headers` constructor. |
| 8 | + |
| 9 | +## Key Breaking Changes for Storage Users |
| 10 | + |
| 11 | +### 1. Response Headers are now `Headers` objects |
| 12 | + |
| 13 | +When you receive a full API response from Storage methods (e.g., via callbacks or promise resolutions that include the response object), the `headers` property of the response is now a standard native `Headers` object (aligned with the Fetch API standard in Node.js 18) rather than a plain JavaScript object. |
| 14 | + |
| 15 | +**Before (Storage v7):** |
| 16 | + |
| 17 | +```js |
| 18 | +const [retrievedFile, apiResponse] = await file.get(); |
| 19 | +const contentType = apiResponse.headers['content-type']; |
| 20 | +``` |
| 21 | + |
| 22 | +**After (Storage v8):** |
| 23 | + |
| 24 | +```js |
| 25 | +const [retrievedFile, apiResponse] = await file.get(); |
| 26 | +// Accessing headers requires the .get() method |
| 27 | +const contentType = apiResponse.headers.get('content-type'); |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Passing Headers in Options |
| 31 | + |
| 32 | +If you pass custom headers in options to Storage methods (which extend `GaxiosOptions`), you can still pass plain objects, as the Storage library will convert them to standard `Headers` internally for the request. However, if you read them back from the prepared options or response, they will be `Headers` objects. |
| 33 | + |
| 34 | +### 3. URL Resolution (`baseURL`) |
| 35 | + |
| 36 | +If you are using custom `baseURL` options or passing relative URLs to methods that accept them, be aware that resolution now strictly follows the standard native `URL` constructor spec (`new URL(url, baseURL)`). |
| 37 | + |
| 38 | +## Upgrade Instructions |
| 39 | + |
| 40 | +Update your `@google-cloud/storage` dependency to version 8: |
| 41 | + |
| 42 | +```sh |
| 43 | +npm install @google-cloud/storage@latest |
| 44 | +``` |
| 45 | + |
| 46 | +## Troubleshooting |
| 47 | + |
| 48 | +- If you encounter `undefined` when accessing headers on the response object, ensure you are using `apiResponse.headers.get('header-name')`. |
0 commit comments