我正在尝试通过针迹功能将mongo查询的结果上传到Azure Blob存储。下面是一个最小的工作示例
exports = async function()
{
const { BlobServiceClient } = require('@azure/storage-blob');
const blobServiceClient = await BlobServiceClient.fromConnectionString("AZURE_CONNECTION_STRING");
const containerName = 'test';
const containerClient = await blobServiceClient.getContainerClient(containerName);
// Create a unique name for the blob
const blobName = 'remote_test_file.txt';
// Get a block blob client
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
console.log('\nUploading to Azure storage as blob:\n\t', blobName);
// Upload data to the blob
const data = 'Hello, World!';
const uploadBlobResponse = await blockBlobClient.upload(data, data.length);
console.log("Blob was uploaded successfully. requestId: ", uploadBlobResponse.requestId);
}
如果我在本地运行它会起作用,但是如果我尝试在Mongo Atlas中运行它会出现以下错误
> error:
failed to eval source for '@azure/storage-blob': failed to eval source for '@azure/core-http': failed to load module 'crypto'
> trace:
StitchError: failed to eval source for '@azure/storage-blob': failed to eval source for '@azure/core-http': failed to load module 'crypto'
at require (<native code>)
at _callee$ (function.js:3:33)
at call (<native code>)
at tryCatch (<anonymous>:55:37)
at invoke (<anonymous>:281:22)
at <anonymous>:107:16
at call (<native code>)
at tryCatch (<anonymous>:55:37)
at invoke (<anonymous>:145:20)
at <anonymous>:180:11
at <anonymous>:3:6
at callInvokeWithMethodAndArg (<unknown>)
at enqueue (<anonymous>:202:13)
at <anonymous>:107:16
at <anonymous>:226:9
at _callee (function.js:1:11)
at apply (<native code>)
at function_wrapper.js:1:11
at <anonymous>:12:1
似乎无法加载内置节点模块crypto
。有什么办法解决吗?