Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
323 stars 55 forks source link

SyntaxError: invalid syntax (python) #1118

Open jpalo opened 1 year ago

jpalo commented 1 year ago

I'm using Gatsby for my SWA, and attempting to upgrade from Gatsby v4 to v5. As a part of the upgrade, I need to also update NODE to 18. All works well locally, but when attempting deployment via Github action, it fails with PYTHON error. I've tried with different versions of Python. It works fine when using Oryx with NODE 14 AND Gatsby4.

npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/node-sass
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c node scripts/build.js
npm ERR! npm ERR! Building: /opt/nodejs/18.14.0/bin/node /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! npm ERR! gyp info it worked if it ends with ok
npm ERR! npm ERR! gyp verb cli [
npm ERR! npm ERR! gyp verb cli   '/opt/nodejs/18.14.0/bin/node',
npm ERR! npm ERR! gyp verb cli   '/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! npm ERR! gyp verb cli   'rebuild',
npm ERR! npm ERR! gyp verb cli   '--verbose',
npm ERR! npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! npm ERR! gyp verb cli   '--libsass_library='
npm ERR! npm ERR! gyp verb cli ]
npm ERR! npm ERR! gyp info using node-gyp@3.8.0
npm ERR! npm ERR! gyp info using node@18.14.0 | linux | x64
npm ERR! npm ERR! gyp verb command rebuild []
npm ERR! npm ERR! gyp verb command clean []
npm ERR! npm ERR! gyp verb clean removing "build" directory
npm ERR! npm ERR! gyp verb command configure []
npm ERR! npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:13:12)
npm ERR! npm ERR! gyp verb `which` failed     at F (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:68:19)
npm ERR! npm ERR! gyp verb `which` failed     at E (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:80:29)
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:89:16
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/isexe/index.js:42:5
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/isexe/mode.js:8:5
npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:207:21)
npm ERR! npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:13:12)
npm ERR! npm ERR! gyp verb `which` failed     at F (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:68:19)
npm ERR! npm ERR! gyp verb `which` failed     at E (/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:80:29)
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/which/which.js:89:16
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/isexe/index.js:42:5
npm ERR! npm ERR! gyp verb `which` failed     at /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/isexe/mode.js:8:5
npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:207:21) {
npm ERR! npm ERR! gyp verb `which` failed   code: 'ENOENT'
npm ERR! npm ERR! gyp verb `which` failed }
npm ERR! npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! npm ERR! gyp verb `which` succeeded python /opt/python/latest/bin/python
npm ERR! npm ERR! gyp ERR! configure error 
npm ERR! npm ERR! gyp ERR! stack Error: Command failed: /opt/python/latest/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack                       ^
npm ERR! npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! npm ERR! gyp ERR! stack 
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:419:12)
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
npm ERR! npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! npm ERR! gyp ERR! System Linux 5.15.0-1034-azure
npm ERR! npm ERR! gyp ERR! command "/opt/nodejs/18.14.0/bin/node" "/github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! npm ERR! gyp ERR! cwd /github/home/.npm/_cacache/tmp/git-cloneqUE5Bj/node_modules/node-sass
npm ERR! npm ERR! gyp ERR! node -v v18.14.0
npm ERR! npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! npm ERR! gyp ERR! not ok 
npm ERR! npm ERR! Build failed with error code: 1
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /github/home/.npm/_logs/2023-03-20T18_47_43_057Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2023-03-20T18_47_35_615Z-debug-0.log

GitHub Actions or Azure Pipelines workflow YAML file

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - main
  schedule:
    - cron: '0 1 * * 1,3,5'

jobs:
  build_and_deploy_job:
    if: github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-22.04 ####ALSO TRIED WITH 18.04
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true
      - name: Setup Python
        uses: actions/setup-python@v2 ####I ADDED THIS ONLY FOR THIS, EARLIER WITH NODE 14 AND GATSBY4 i DIDN'T HAVE THIS AT ALL
        with:
          # Version range or exact version of a Python version to use, using SemVer's version range syntax.
          python-version: "3.9.x" ####ALSO TRIED WITH 2.7.x, SAME ERROR ALSO WITHOUT THIS
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ICY_SEA_XYZXYZ }}
          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 source code path - optional
          output_location: "public" # Built app content directory - optional
        env:
          AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
          NPM_CONFIG_LEGACY_PEER_DEPS: true ####THIS I ADDED AS A TEST DURING GATSBY5 UPDATE, NOT USING IT EARLIER
          ###### 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@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ICY_SEA_XYZXYZ }}
          action: "close"

staticwebapp.config.json file

{
    "platform": {
        "apiRuntime": "node:18"
    },
    "routes": [
        { ...NOT RELEVANT; SO REMOVED }
    ]
}

Source repo not public

package.json has this:

  "engines": {
    "node": ">=18.0.0"
  },

Expected behavior Build would succeed.

jpalo commented 1 year ago

Any comments, as this issue still persists?