facing issue to setup nodejs version 18 for azure function via serverless deploy

111 Views Asked by At

I am trying to deploy NodeJS code to azure function via serverless framework. It is working correctly for node 14 but facing issue when I tried to deploy is node 18.

Ideally after deployment FUNCTIONS_EXTENSION_VERSION should set to ~4 but it is set as ~3

I am using below serverless yml file

service: node-azure

provider:
  name: azure
  region: East US
  stage: dev
  runtime: nodejs18

plugins:
  - serverless-azure-functions

package:
  exclude:
    - node_modules/**
    - .gitignore
    - package.json
    - .git/**

functions:
  hello:
     handler: handler.hello
     events:
       - http: true
         x-azure-settings:
           authLevel: anonymous
1

There are 1 best solutions below

4
SiddheshDesai On

I tried creating and deploying Nodejs Function with serverless and yes by default it will take nodejs12 as a Function runtime for nodejs template, But nodejs14, nodejs18, nodejs20 are also supported parameters:-

Note- Runtime version 3 will also work but its going to be deprecated so you can upgrade it to Version 4

Refer my Github Repository for the serverless project.

My Default server.yml with nodejs18:-


service: functionserverless1


frameworkVersion: '3'

provider:
  name: azure
  region: West US 2
  runtime: nodejs18
  # os: windows  # windows is default, linux is available
  # prefix: "sample"  # prefix of generated resource name
  subscriptionId: 0xxxxxxxx6e97cb2a7
  # type: premium  

  environment: 
    VARIABLE_FOO: 'foo'

 
plugins: # look for additional plugins in the community plugins repo: https://github.com/serverless/plugins
  - serverless-azure-functions

# you can add packaging information here
package:
  patterns:
    # - '!exclude-me.js'
    # - '!exclude-me-dir/**'
    - '!local.settings.json'
    - '!.vscode/**'
    # - include-me.js
    # - include-me-dir/**

functions:
  hello:
    handler: src/handlers/hello.sayHello
    events:
      - http: true
        methods:
          - GET
        authLevel: anonymous 

  goodbye:
    handler: src/handlers/goodbye.sayGoodbye
    events:
      - http: true
        methods:
          - GET
        authLevel: anonymous

Commands:-

Refer here for more details.

npm i -g serverless
sls create -t azure-nodejs -p FunctionServerless1
cd FunctionServerless1
npm install
az login
az account set -s <subscription-id>
az ad sp create-for-rbac --name siliconserverless

In command Prompt:-

Use SET, For Bash use Export, For Powershell use $env:

I am using command prompt:-

SET AZURE_SUBSCRIPTION_ID=xxxxxxa7
SET AZURE_TENANT_ID=xxxxxxxx395
SET AZURE_CLIENT_ID=xxxxxxfae
SET AZURE_CLIENT_SECRET=xxxWrYVJc8m

After setting all the environment variables deploy the Function by the command below:-

serverless deploy

Output:-

enter image description here

FUNCTIONS_WORKER_RUNTIME:node

enter image description here

enter image description here

Upgrade the Runtime version to 4 via Configuration settings:-

FUNCTIONS_EXTENSION_VERSION: 4

enter image description here

enter image description here

In order to Run the Function from Portal > Code + Test > Add the CORS settings below:-

enter image description here

enter image description here

If the issue persists, Raise a github issue here.