1

I've got a project which utilizes the openpgpjs library as a dependency, and I'm WebPacking up this whole application for deployment on an Azure Functions to resolve cold start issues.

The Azure functions work fine when running locally in a non-Webpacked format, but as soon as I WebPack up the files I keep getting the error at runtime:

"mscorlib: Error: Cannot find module 'crypto'"

The code which is triggering this error appears to be from Openpgpjs's util.js.

This whole file is here: https://github.com/openpgpjs/openpgpjs/blob/master/src/util.js

The offending code snipper is below:

/**
   * Get native Node.js crypto api. The default configuration is to use
   * the api when available. But it can also be deactivated with config.use_native
   * @return {Object}   The crypto module or 'undefined'
   */
  getNodeCrypto: function() {
    if (!this.detectNode() || !config.use_native) {
      return;
    }

    return require('crypto');
  },

For the life of me, I can't figure out why this is happening and I can't get the error to go away.

I'm using my own script pack-git to do the Webpacking, etc. However, I get the same behavior if I use Azure's function pack. (Which didn't exist when I started writing the code for master-pack.

As a result I think this has something to do with the way the library is playing with WebPack, but I'm not sure where to begin in figuring it out/troubleshooting.

Does anyone have any ideas on what is going wrong, or at least ideas to help me further isolate the problem?

------------------- EDIT ---------------------

I've created a simple project that reproduces the issue when run through Funcpack, which is using Webpack.

Reproduction Steps:

  1. Install funcpack, and azure-functions-cli globally:

    npm install -g funcpack azure-functions-cli

  2. Clone the following repo:

    git clone https://github.com/securityvoid/funcpack-bug.git

  3. Run an npm install while in the folder you cloned into:

    npm install

  4. Start the Azure Function with azure-functions-cli from within the base of the cloned repository.

    func run aaaa

  5. Navigate to the following URL and validate you get a blank page back, which shows its working:

    http://localhost:7071/Test

  6. Stop the azure-functions-cli by closing the window.

  7. Run funcpack in the base of the directory:

    funcpack

  8. Repeat steps 4-5

NOTE: This time you get an error about the module crypto not being found.

Doug
  • 6,446
  • 9
  • 74
  • 107
  • Hey, this is because this is a native module. I've got a feature to allow you to ignore modules in a feature branch right now. I'm going to try and merge to master and publish an update tonight. – Chris Anderson Jun 29 '17 at 01:10
  • Awesome! Thank-you! – Doug Jun 29 '17 at 01:16
  • Okay, I still have issues even running the dev branch that has those changes merged. – Doug Jun 29 '17 at 15:10
  • Hey I've updated the latest release on npm. Can you try again with crypto added to your ignored modules list? You can see a sample of that config here: https://github.com/Azure/azure-functions-pack/blob/master/sample/funcpack.config.json – Chris Anderson Jul 01 '17 at 00:15
  • @ChrisAnderson-MSFT No luck :-(. Still reproduces the issue. – Doug Jul 01 '17 at 01:23
  • 1
    @ChrisAnderson-MSFT If you pull the git repo https://github.com/securityvoid/funcpack-bug.git you can see for yourself. Its a really quick, simple repro. – Doug Jul 01 '17 at 01:24
  • Cool. I'll take a look. I've a few guesses at what might cause that. I'll check that I'm actually passing the config properly. If so, it's like a webpack issue I'll have to try to debug (since this is basically a utility script about webpack). – Chris Anderson Jul 03 '17 at 15:57

0 Answers0