NodeJS 在Azure中部署Web应用程序时出现权限被拒绝错误

3pvhb19x  于 2023-10-17  发布在  Node.js
关注(0)|答案(1)|浏览(153)

我试图在Azure中部署一个Web应用程序,使用Github Actions构建成功,但随后容器在Azure中崩溃,并且我得到一个关于'cross-env'包的权限被拒绝的错误,这是我的package.json中的依赖项。该项目在当地运行良好。
控制台

2023-10-12T21:27:43.947743248Z 
2023-10-12T21:27:43.947747649Z npm start
2023-10-12T21:27:45.373528228Z npm info using [email protected]
2023-10-12T21:27:45.373565332Z npm info using [email protected]
2023-10-12T21:27:45.459141307Z 
2023-10-12T21:27:45.459175710Z > [email protected] start
2023-10-12T21:27:45.459182911Z > cross-env NODE_ENV=production nodemon ./bin/www
2023-10-12T21:27:45.459188211Z 
2023-10-12T21:27:45.531346836Z sh: 1: cross-env: Permission denied

2023-10-12T21:27:51.870Z ERROR - Container MyProject didn't respond to HTTP pings on port: 8080, 
failing site start. 
2023-10-12T21:27:51.873Z INFO  - Stopping site MyProject because it failed during startup.

package.json

"scripts": {
    "start": "cross-env NODE_ENV=production nodemon ./bin/www",
    "dev": "cross-env NODE_ENV=development nodemon ./bin/www",
  },
  "engines": {
    "node": ">=18.17.0"
  },
  "dependencies": {
    "cross-env": "^5.2.0",
    "npm": "^9.6.4",
     "nodemon": "^1.19.0",
    ...
    ...

  },
hec6srdp

hec6srdp1#

我试着在我的**package.json中使用cross-env**,并添加了一个启动命令来使用cross-env初始化示例nodejs express应用程序。在验证应用程序在本地成功运行后,我通过Github Actions部署了它,它成功运行参考下面:-

本地安装跨环境命令:-

npm i cross-env

我的包。json:-

{
  "name": "myexpressapp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "cross-env NODE_ENV=production node ./bin/www"
  },
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "cross-env": "^7.0.3",
    "debug": "~2.6.9",
    "ejs": "^3.1.9",
    "express": "^4.18.2",
    "http-errors": "~1.6.3",
    "morgan": "~1.9.1"
  }
}

我将本地代码推送到Github存储库,并通过Azure Web应用部署中心部署,如下所示:

我的github工作流程:-

name: Build and deploy Node.js app to Azure Web App - valleywebapp93

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: '18.x'

      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm run test --if-present

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: node-app
          path: .

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: node-app

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'valleywebapp93'
          slot-name: 'production'
          publish-profile: ${{ secrets.AzureAppService_PublishProfile_37c199061c544aaf9f9e913c30f41b97 }}
          package: .

我的仓库:-

Reference

输出:-

相关问题