Daniel Serrão
Daniel Serrão

Reputation: 511

azure-storage not working with web pack (azure-functions-pack) server side

I made an Azure Function micro service using Node.js and I'm using the npm module azure-storage to insert files in a Blob Storage.

Locally is working fine, but when deploying to development environment, it is executed a script that executes azure-functions-pack and generate a bundle with the service code and all the required npm modules. Then when making a request to the micro service, it return a status code 500 and in the logs the error is the following:

System.Exception : Error: Cannot find module "."
at webpackMissingModule (D:\home\site\wwwroot\.funcpack\index.js:238044:68)
at Object.<anonymous> (D:\home\site\wwwroot\.funcpack\index.js:238044:147)
at __webpack_require__ (D:\home\site\wwwroot\.funcpack\index.js:21:30)
...

I only know that the problem is the azure-storage module because If I comment the "azureStorage = require('azure-storage');" , then start working. I also tried the npm module fast-azure-storage without success and until now I was not able to find a workaround for this problem. The code that uses this module is the following:

    const blobSvc = azureStorage.createBlobService(storageConnectionString);
    const writeStream = blobSvc.createWriteStreamToBlockBlob('containerName', fileName);

    return new Promise(function (resolve) {
      writeStream.write(svgString);
      writeStream.on('close', () => {
        resolve('https://' + storageAccount + '.blob.core.windows.net/containerName/' + fileName);
      });

      writeStream.end();
    });

The version of azure-storage is 2.6.0. Thanks for any help.

Upvotes: 1

Views: 380

Answers (2)

Daniel Serr&#227;o
Daniel Serr&#227;o

Reputation: 511

Actually the problem wasn't the azure-storage module, but the node-chartist module which for some reason also was causing problems in other modules. After remove node-chartist all the modules started working perfectly.

Upvotes: 1

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35144

Not a direct answer to your question - but you should use output binding feature of Azure Function to insert Blobs instead of doing that manually with library calls.

If you do that, you won't have to import the package, so it will also solve your problem.

Read more about output bindings in docs, there is a node example there too.

Upvotes: 1

Related Questions