Reputation: 543
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/static-web-apps-deploy@v0.0.1-preview
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/static-web-apps-deploy@v0.0.1-preview
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?
Upvotes: 8
Views: 3881
Reputation: 271
Another solution to this is to add the following environment variable to your job in the github actions file:
env:
NODE_VERSION: 16
Upvotes: 3
Reputation: 12114
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...
Upvotes: 18
Reputation: 543
Documentation says that supported Node versions are only as high as LTS. 12.8 currently. You can't use the Azure/static-web-apps-deploy@v0.0.1-preview action with v14.x right now.
I solved the problem by using github-actions and pushing the build to the azure storage.
Upvotes: 0