Fix the Azure Function Node.js GitHub Actions Windows workflow
post
When deploying Node.js-based Azure Functions using GitHub Actions, you might face an issue with the Windows workflow. In the latest template, there is an issue in the build step where the actions/upload-artifact action fails to upload the artifact due to too many files. The problem is caused by the node_modules folder, which contains many files (even for a starter Azure Function project).
Another issue I spotted is that if the build step is successful, the deployment job will deploy all the dependencies (including the development dependencies) to the Azure Function App. Deploying the development dependencies is not recommended as it increases the deployment size and should not be required to run your functions.
Fix the build artifact issue
To fix the issue, you must exclude the node_modules folder from the artifact upload and install an npm during the deployment. You can do this using the ignore pattern in the actions/upload-artifact action.
Updates to the actions/upload-artifact action
1
2
3
4
5
6
7
8
- name:Upload artifact for deployment jobuses:actions/upload-artifact@v4with:name:node-apppath:| .
!./src # Exclude the source code (optional)
!./node_modules # Exclude the node_modules folder
tip
I excluded the source files (!./src) from being published to the Azure Function as they are not required for running the functions. You are free to include/exclude those.
Fix the deployment dependencies issue
To fix the deployment dependencies issue, you must install only the production dependencies during the deployment. You can use the --omit=dev flag in the npm install command. Add the following step to the deployment job after the actions/download-artifact action to install the production dependencies.
Install the production dependencies during deployment
1
2
3
4
5
6
- name:"Install production dependencies"shell:pwshrun:| pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm i --omit=dev
popd
The complete updated workflow
Here is the complete updated workflow with the above fixes.