Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] Azure/SWA: dependency on outdated @azure/functions v3 results in broken deployments and HTTP status 500 #7154

Open
rondonjon opened this issue Dec 13, 2024 · 1 comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working

Comments

@rondonjon
Copy link

rondonjon commented Dec 13, 2024

Which component is affected?

Qwik Runtime

Describe the bug

Problem

Having installed the azure-swa adapter and successfully built and deployed my app, I find the target environment responding with an HTTP status code 500.

There is almost no information (stack traces etc.) available in Azure. Application Insights shows that the requests have been processed by /api/render within reasonable time, but with status code 500.

To reproduce

Repository (just a qwik starter repo with azure-swa added): https://github.com/rondonjon/qwik-swa-deployment-repro

Deployment URL: https://ashy-wave-05e72ba03-preview.westeurope.4.azurestaticapps.net

Reproduction

https://ashy-wave-05e72ba03-preview.westeurope.4.azurestaticapps.net

Steps to reproduce

  • initialize a new qwik app
  • add the azure swa adapter
  • build the app
  • deploy the app with npx swa deploy
  • open the displayed deployment URL in a browser
  • browser will display an http status code 500

System Info

 System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 AMD Ryzen 9 7945HX with Radeon Graphics
    Memory: 15.17 GB / 31.19 GB
  Binaries:
    Node: 20.18.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @builder.io/qwik: ^1.11.0 => 1.11.0
    @builder.io/qwik-city: ^1.11.0 => 1.11.0
    typescript: 5.4.5 => 5.4.5
    undici: * => 7.1.0
    vite: 5.3.5 => 5.3.5

Additional Information

I have tried to run the Azure build locally with swa start. Instead of a 500, the app is returning 404 for all routes, but it does serve static assets like the robots.txt file.

While starting up, the app displays the following messages:

[api] Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
[api] [2024-12-16T15:49:09.459Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

I found a pointer here that an additional file named local.settings.json is needed. I have put the suggested contents into azure-functions/local.settings.json. The first message has now disappeared.

{
	"IsEncrypted": false,
	"Values": {
		"FUNCTIONS_WORKER_RUNTIME": "node",
		"AzureWebJobsStorage": "UseDevelopmentStorage=true"
	},
	"Host": {
		"LocalHttpPort": 7071,
		"CORS": "*",
		"CORSCredentials": false
	}
}

The second message seems to be caused by a version mismatch between the @azure/functions package that Qwik uses (3.5.1) and the Azure Core Function Tools package that the SWA package automatically downloads during the Azure build. According to func-core-tools.js in the @azure/static-web-apps-cli package, all node.js versions above 13 will (now) download major version 4 of the Azure Core Function Tools.

function detectTargetCoreToolsVersion(nodeVersion) {
    // Pick the highest version that is compatible with the specified Node version
    if (nodeVersion >= 14 && nodeVersion <= 20)
        return 4;
    if (nodeVersion >= 10 && nodeVersion < 14)
        return 3;
    if (nodeVersion >= 8 && nodeVersion < 10)
        return 2;
    // Fallback to the latest version for Unsupported Node version
    return 4;
}

This requires some adjustments. Among some other changes, the functions.json file, which the Qwik adapter currently generates, has been replaced.

@rondonjon rondonjon added STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working labels Dec 13, 2024
@rondonjon rondonjon reopened this Dec 13, 2024
@rondonjon rondonjon changed the title [🐞] Azure/SWA: app returns HTTP status 500 [🐞] Azure/SWA: deployed app returns HTTP status 500 Dec 13, 2024
@rondonjon rondonjon changed the title [🐞] Azure/SWA: deployed app returns HTTP status 500 [🐞] Azure/SWA: outdated dependency on @azure/functions v3 results in broken deployments and HTTP status 500 Dec 16, 2024
@rondonjon rondonjon changed the title [🐞] Azure/SWA: outdated dependency on @azure/functions v3 results in broken deployments and HTTP status 500 [🐞] Azure/SWA: dependency on outdated @azure/functions v3 results in broken deployments and HTTP status 500 Dec 16, 2024
@rondonjon
Copy link
Author

rondonjon commented Dec 19, 2024

Hello @wmertens and @shairez, it seems that you have worked on this adapter in the past. Could you please check if it is still working for you and share a quick update?

I have tried to upgrade manually to v4 by patching the config files and replacing functions.json with an index.js file with a modified Azure function handler (the context and request parameters have been flipped and modified). Eventually I got the bundle to display the start page, but it produces 404s for all other routes. I suspect that more changes may be needed in the vite adapter and the request handler, but that part of the code kind of overwhelms me 🫨

Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant