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

Wrongly reported Node compatibility #791

Open
itpropro opened this issue Jan 2, 2024 · 11 comments
Open

Wrongly reported Node compatibility #791

itpropro opened this issue Jan 2, 2024 · 11 comments

Comments

@itpropro
Copy link

itpropro commented Jan 2, 2024

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 itpropro changed the title Wrongly reported Node compatability Wrongly reported Node compatibility Jan 2, 2024
@itpropro
Copy link
Author

itpropro commented Jan 23, 2024

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.

@jonverrier
Copy link

A bump for this one.

@Manaiakalani
Copy link

+1 🙂

@DuncWatts
Copy link

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.

@jonverrier
Copy link

jonverrier commented Feb 12, 2024

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

@DuncWatts
Copy link

DuncWatts commented Feb 12, 2024

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

@milesflavel
Copy link

milesflavel commented Mar 11, 2024

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:

export function isCoreToolsVersionCompatible(coreToolsVersion: number, nodeVersion: number): boolean {
// 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;
case 3:
return nodeVersion >= 10 && nodeVersion <= 14;
case 2:
return nodeVersion >= 8 && nodeVersion <= 10;
default:
return false;
}
}

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?

@sk22
Copy link

sk22 commented Apr 15, 2024

Until #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.

@sebastianrogers
Copy link

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
Copy link

Annoyingly its already fixed in the source see

return nodeVersion >= 14 && nodeVersion <= 20;

@TianshengC
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants