How do you deploy an Azure function app with pnpm?
I'm using a rush monorepo and the rush deploy task which works great locally. The problem is that I'm unable to get ALL of my pnpm node_modules dependencies AND get my Azure function started in the cloud runtime environment
Min repro project here: https://github.com/luisnaranjo733/pnpm-rush-azure-functions
After running rush deploy
, I get a nice ready to deploy project at the common/deploy
path. When I try to deploy the commmon/apps/functions
directory which contains the package.json for my functions project, Azure Functions mostly works except for when I import a dependency that itself has a dependency on something else.
This makes sense because of the way pnpm node_modules works, but in this case it's causing a huge headache with Azure Functions. See screenshot below for more details
The green highlighted node_modules is the one that only contains the dependencies declared by my project. As expected, only @azure/service-bus is there because that is the only dependency my functions project is using.
The orange highlighted node_modules is the pnpm global content adressable module store. This is where the dependencies of @azure/service-bus end up such a @azure/core-amqp.
When running locally via npm run start
, my function is able to resolve the import to @azure/service-bus
from the green node_modules and its internal dependencies from the orange node_modules. When running on the cloud runtime environment, this doesn't work :(
I can deploy the common/deploy/apps/functions
project which works fine on the cloud runtime until I try to import @azure/service-bus which fails because it can't find its internal dependencies such as @azure/core-amqp.
Example cloud runtime file system when deploying the common/deploy/apps/functions folder
I see a few possible paths forward, but no clear winner
- Revert back to npm, which sucks because I really wanted to use pnpm+rush.
- Configure pnpm to copy and flatten my
common/deploy/apps/functions/node_modules
indistinguishable from a npm or yarn one (no symlinks to global content addressable module store). But this kind of negates the whole point of pnpm - Configure Azure Functions cloud runtime environment to use some kind of pnpm mode and figure out what's happening and solve it for me
Has anyone trodden this path or have any words of wisdom? Thanks, Luis
You can use
cp -LR
to resolve the symlinks: