[英]Static Web App Deploy with Azure using specific Node version
I am trying to deploy a static web app using Azure services with Github Actions.我正在尝试部署 static web 应用程序,使用 Azure 服务和 ZE1ADBCBB92C602D0B3EAB619。
The problem is, I need to run a script using NodeJS.问题是,我需要使用 NodeJS 运行脚本。 I am using ESM modules which are working fine in Node v14.
我正在使用在 Node v14 中运行良好的 ESM 模块。 The problem is, during build task Azure (or github) uses v12.8 (LTS I guess) where ESM modules are not supported.
问题是,在构建任务 Azure(或 github)期间使用不支持 ESM 模块的 v12.8(我猜是 LTS)。
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.尽管如此,构建过程仍然使用 12.8。
What am I doing wrong and is it possible to use a specific version in my case?我做错了什么,是否可以在我的情况下使用特定版本?
Documentation says that supported Node versions are only as high as LTS.文档说支持的 Node 版本只和 LTS 一样高。 12.8 currently.
目前 12.8。 You can't use the Azure/static-web-apps-deploy@v0.0.1-preview action with v14.x right now.
你现在不能在 v14.x 中使用 Azure/static-web-apps-deploy@v0.0.1-preview 操作。
I solved the problem by using github-actions and pushing the build to the azure storage.我通过使用 github-actions 并将构建推送到 azure 存储解决了这个问题。
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 .对于像我这样在 12.8(实际上是 14.x)之后提出这个问题的人来说,它们被认为是“遗留”版本,但即使在 v1 中,static-web-apps-deploy 仍继续使用旧版本的 Node(在我的情况是 14.19.1),我在Edi Wang 的博客文章中找到了答案。 It says to add an "engine" property to your package.json, with a "node" property specifying the version you need.
它说要向 package.json 添加“引擎”属性,并使用“节点”属性指定您需要的版本。 Since I wanted v16 or above, I added the following:
由于我想要 v16 或更高版本,我添加了以下内容:
"engines": {
"node": ">=16.0.0"
},
This caused Oryx to find and download Node v17.6.0:这导致 Oryx 找到并下载 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...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.