static-web-apps-cli
static-web-apps-cli copied to clipboard
Wrongly reported Node compatibility
When running the swa cli, for example with pnpm dlx @azure/static-web-apps-cli start app/output --api-location app/server
, it outputs
✖ Found Azure Functions Core Tools v4 which is incompatible with your current Node.js v20.10.0.
✖ See https://aka.ms/functions-node-versions for more information.
This is not related to the actual compatibility with Node 20, but is at least a wrong statement in the output, as linked docs/learn site clearly states that Node.js v20.x is supported: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=javascript%2Cwindows%2Cazure-cli&pivots=nodejs-model-v4#supported-versions. Is there any reason, the current LTS version of Node is not supported, while Node 16, which is eol since September 2023 still is?
Any news on this or #756 @thomasgauvin ? It completely blocks even running the cli to test SWAs, even if they would be running on Node 18 in production.
A bump for this one.
+1 🙂
What is the a workaround to this issue? I cannot seem to run the SWA locally with a c# function api added, although it does work correctly when deployed to Azure.
What is the a workaround to this issue? I cannot seem to run the SWA locally with a c# function api added, although it does work correctly when deployed to Azure.
Not sure for C#, but for javascript You can build a local node.js app with embedded calls to your 'api' paths & then run your app against localhost:1337. Tedious but works for development until they fix this. Maybe there is a C# equivalent.
var host = "127.0.0.1"; var port = 1337; var express = require("express");
var app = express();
app.get('/api/myapi', function routeHandler(req, res) { // call out to yout index.js file here ... });
app.use('/', express.static('./public')); app.listen(port, host);
Thank you, that gets me going again, as long as I start the SWA and C# Function app separately this is working for me.
var proxy = require('express-http-proxy');
var app = require('express')();
app.use('/api', proxy('localhost:7071', {
proxyReqPathResolver: function (req) {
return "/api" + req.url;
}}));
app.use('/', proxy('localhost:4280'));
app.listen(3001, "127.0.0.1");
Would like to confirm that this is still an issue on v1.1.7 even with the changes from #809
New SWA with C# API gives this output:
Welcome to Azure Static Web Apps CLI (1.1.7)
Using configuration "temp" from file:
C:\Users\Miles\Projects\temp\swa-cli.config.json
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure. *
***********************************************************************
✖ Found Azure Functions Core Tools v4 which is incompatible with your current Node.js v20.5.0.
✖ See https://aka.ms/functions-node-versions for more information.
swa-cli.config.json:
{
"$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
"configurations": {
"temp": {
"appLocation": ".",
"apiLocation": "api",
"outputLocation": "dist",
"apiLanguage": "dotnetisolated",
"apiVersion": "8.0",
"appBuildCommand": "npm run build",
"run": "npm run start"
}
}
}
It appears that the issue is related to this function: https://github.com/Azure/static-web-apps-cli/blob/b9675b31e0cb022238a49975882c3e209ae0e094/src/core/func-core-tools.ts#L41-L53 Which should probably align closely with the versions listed here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=javascript%2Cwindows%2Cazure-cli&pivots=nodejs-model-v4#supported-versions
That said, do the func core tools actually depend on the nodejs version, or is that only for running node functions?
Until https://github.com/Azure/static-web-apps-cli/pull/818 is released in a new version, here's an ugly workaround that might just be enough for local development: Open node_modules/@azure/static-web-apps-cli/dist/core/func-core-tools.js
in an editor and change line 45 like this (or anyway else; just make sure the function returns true):
function isCoreToolsVersionCompatible(coreToolsVersion, nodeVersion) {
// Runtime support reference: https://docs.microsoft.com/azure/azure-functions/functions-versions?pivots=programming-language-javascript#languages
switch (coreToolsVersion) {
case 4:
- return nodeVersion >= 14 && nodeVersion <= 18;
+ return nodeVersion >= 14 && nodeVersion <= Infinity;
Of course, this "fix" will break once node_modules
are reinstalled.
If using a GitHub CodeSpace you can find the file here /usr/local/share/nvm/versions/node/v20.12.1/lib/node_modules/@azure/static-web-apps-cli/dist/core/func-core-tools.js
Annoyingly its already fixed in the source see https://github.com/Azure/static-web-apps-cli/blob/dc37b72f98ca6cb6f9cbcb5b0ecadf66a9dbe869/src/core/func-core-tools.ts#L45
C:\Users{username}\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\core\func-core-tools.js
I have the same issue. I installed the azure tool globally on windows and found this file.
Then change line 45 return nodeVersion >= 14 && nodeVersion <= 20;
Then it worked well.
I hope this could be helpful for others.