I am trying to deploy a static web app using Azure services with Github Actions.
The problem is, I need to run a script using NodeJS. I am using ESM modules which are working fine in Node v14. The problem is, during build task Azure (or github) uses v12.8 (LTS I guess) where ESM modules are not supported.
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/[email protected]
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LEMON_GLACIER_0C510BD03 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "api" # Api source code path - optional
app_artifact_location: "public" # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/[email protected]
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LEMON_GLACIER_0C510BD03 }}
action: "close"
I was trying to specify the Node version using this step:
- name: Setup Node 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'
Still, the build process uses 12.8.
What am I doing wrong and is it possible to use a specific version in my case?
For those like me who came to this question well after 12.8 (and indeed 14.x) were considered "legacy" releases, and yet static-web-apps-deploy, even at v1, continues to use an old version of Node (in my case, 14.19.1), I found the answer on a blog post by Edi Wang. It says to add an "engine" property to your package.json, with a "node" property specifying the version you need. Since I wanted v16 or above, I added the following:
"engines": {
"node": ">=16.0.0"
},
This caused Oryx to find and download Node v17.6.0:
Detecting platforms...
Detected following platforms:
nodejs: 17.6.0
Version '17.6.0' of platform 'nodejs' is not installed. Generating script to install it...
You may need to modify the version upward as time goes on. For instance, as I write this, the LTS version of Node is v22.18.0. What Oryx detects and installs, however, may differ (especially since 22.17.0 is the highest version I see here: https://github.com/microsoft/Oryx/blob/main/platforms/nodejs/versions/bookworm/versionsToBuild.txt; that will likely be updated, but nonetheless, YMMV as they say).
Another solution to this is to add the following environment variable to your job in the github actions file:
env:
NODE_VERSION: 16
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With