gpt4 book ai didi

node.js - 使用特定 Node 版本通过 Azure 部署静态 Web 应用程序

转载 作者:行者123 更新时间:2023-12-03 00:01:48 27 4
gpt4 key购买 nike

我正在尝试使用 Azure 服务和 Github Actions 来部署静态 Web 应用。

问题是,我需要使用 NodeJS 运行脚本。我正在使用 ESM 模块,这些模块在 Node v14 中运行良好。问题是,在构建任务期间,Azure(或 github)使用 v12.8(我猜是 LTS),其中不支持 ESM 模块。

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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bf8ffeaffe2e8a6fceee9a6eafbfbf8a6efeefbe7e4f2cbfdbba5bba5baa6fbf9eefde2eefc" rel="noreferrer noopener nofollow">[email protected]</a>
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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a595e4b5e4349075d4f48074b5a5a59074e4f5a4645536a5c1a041a041b075a584f5c434f5d" rel="noreferrer noopener nofollow">[email protected]</a>
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LEMON_GLACIER_0C510BD03 }}
action: "close"

我试图使用此步骤指定 Node 版本:

- name: Setup Node 14.x
uses: actions/setup-node@v1
with:
node-version: '14.x'

构建过程仍然使用 12.8。

我做错了什么,是否可以在我的情况下使用特定版本?

最佳答案

对于像我这样在 12.8(实际上是 14.x)被认为是“遗留”版本之后才提出这个问题的人来说,然而 static-web-apps-deploy,即使在 v1 中,仍然继续使用旧版本 Node (在我的例子中,14.19.1),我在 a blog post by Edi Wang 上找到了答案。它表示要向 package.json 添加一个“engine”属性,并使用一个“node”属性指定您需要的版本。由于我想要 v16 或更高版本,因此我添加了以下内容:

  "engines": {
"node": ">=16.0.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...

关于node.js - 使用特定 Node 版本通过 Azure 部署静态 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63810325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com