Bug: Expected signal to be an instanceof AbortSignal in Netlify CLI v16.2.0+
Describe the bug
This is a tricky issue to describe, but I can reproduce it with a simple example. The issue is observed specifically when using Netlify CLI v16.2.0 and onwards. Everything works as expected in < v16.1.0. The problem does not occur in other environments like running from the file system or in production. The issue manifests as a TypeError: "Expected signal to be an instanceof AbortSignal".
Some change in the 16.2.0 release appears to have introduced errors when running a fairly stable library. It seems to affect the Node environment. I've checked the changelog for clues on what might have caused this but didn't find any direct leads.
I have tried node v16 -> v20
Steps to reproduce
To Reproduce
- Install Netlify CLI v16.2.0 or newer.
- Run the provided Netlify Function that interacts with Azure Blob Storage.
- Observe the TypeError mentioned.
Expected Behavior
The function should successfully generate a SAS (Shared Access Signature) for Azure Blob Storage without any issues.
Actual Behavior
Receiving a TypeError: "Expected signal to be an instanceof AbortSignal".
TypeError: Expected signal to be an instanceof AbortSignal
...
Environment
- Node version: 14+
- Netlify CLI version: 16.2.0+
- Operating System: macOS 13.5.2
Example Code
You can find the example code below. Note: You will need Azure account keys to fully reproduce the issue. Setting up Azure keys can be cumbersome, but you can follow the documentation here: Azure Account Keys Manage.
import{ BlobServiceClient, StorageSharedKeyCredential, generateAccountSASQueryParameters, AccountSASPermissions } from '@azure/storage-blob'
const AZURE_STORAGE_CONNECTION_STRING= ""
const AZURE_STORAGE_ACCOUNT = ""
const AZURE_STORAGE_ACCOUNT_KEY = ""
const getFileSas = async(container, filename) => {
const sharedKeyCredentials = new StorageSharedKeyCredential(
AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_ACCOUNT_KEY
)
const HOUR = 60 * 60 * 1000
const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING)
const startDate = new Date(new Date().getTime() - (HOUR)) // 1 Hour Ago, daylight saving prevention
const expiryDate = new Date(new Date().getTime() + (24 * HOUR)) // 24 Hours From Now
const sasSignature = {
startsOn: startDate,
expiresOn: expiryDate,
permissions: AccountSASPermissions.parse('rwdlac'),
protocol: 'https',
resourceTypes: 'sco',
services: 'b',
version: '2020-02-10'
}
try {
const containerClient = blobServiceClient.getContainerClient(container)
await containerClient .createIfNotExists({ access: 'blob' })
const SAS = generateAccountSASQueryParameters(sasSignature, sharedKeyCredentials)
debugger
return { 'sas' : `https://${AZURE_STORAGE_ACCOUNT}.blob.core.windows.net/${container}/${filename}?${SAS}` }
} catch (error) {
debugger
console.log('Error in getFileSas', error)
}
}
// File System Example
// getFileSas('mycontainer', 'myfilename').then((sas) => {
// console.log('SAS', sas)
// })
// .catch((error) => {
// console.log('Error', error)
// })
// Netlify Function
export const handler = async (event) => {
debugger
const sas = await getFileSas('mycontainer', 'myfilename')
console.log('SAS', sas)
debugger
return {
statusCode: 200,
headers: { 'content-type': 'text/html; charset=utf-8' },
body: JSON.stringify(sas)
}
}
Additional Information
I tried many different polyfill libraries with no success. It took a long time to track down it was caused by the cli.
Configuration
[build] functions = "build/functions" command = "npm run build"
[dev] functions = "netlify/functions"
Environment
System: OS: macOS 13.5.2 CPU: (36) x64 Intel(R) Xeon(R) W-2191B CPU @ 2.30GHz Memory: 15.61 GB / 128.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.6.1 - /usr/local/bin/node Yarn: 1.22.17 - ~/Applications/n/bin/yarn npm: 9.5.1 - /usr/local/bin/npm pnpm: 6.32.10 - ~/Applications/n/bin/pnpm npmGlobalPackages: netlify-cli: 16.1.0