static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Wrongly reported Node compatibility

Open itpropro opened this issue 1 year ago • 8 comments

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?

itpropro avatar Jan 02 '24 03:01 itpropro

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.

itpropro avatar Jan 23 '24 01:01 itpropro

A bump for this one.

jonverrier avatar Feb 06 '24 17:02 jonverrier

+1 🙂

Manaiakalani avatar Feb 08 '24 09:02 Manaiakalani

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.

DuncWatts avatar Feb 11 '24 23:02 DuncWatts

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);

jonverrier avatar Feb 12 '24 09:02 jonverrier

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");

DuncWatts avatar Feb 12 '24 19:02 DuncWatts

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?

milesflavel avatar Mar 11 '24 12:03 milesflavel

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.

sk22 avatar Apr 15 '24 08:04 sk22

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

sebastianrogers avatar May 09 '24 18:05 sebastianrogers

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

sebastianrogers avatar May 09 '24 19:05 sebastianrogers

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.

TianshengC avatar May 15 '24 23:05 TianshengC