typescriptpulumi

Pulumi - Errors on NodeJS14 - trying to switch to NodeJS21 - unable to compile TypeScript


I'm a first time user of Pulumi. I was trying a Saas Template from here: https://github.com/SimonHoiberg/saas-template

First error on "pulumi up"

 aws:lambda:Function (post-confirmation-fn):
    error: 1 error occurred:
        * error creating Lambda Function (1): InvalidParameterValueException: The runtime parameter of **nodejs14.x** is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs20.x) while creating or updating functions.
    {
      RespMetadata: {
        StatusCode: 400,
        RequestID: "bd01d1cb-9897-456f-89ab-2e75ea03f432"
      },
      Message_: "The runtime parameter of nodejs14.x is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (nodejs20.x) while creating or updating functions.",
      Type: "User"
    }

So installed Node 21.7 and searched for NodeJs14 in all files, changing 'nodejs14.x' to 'nodejs21.x'

Then got this error:

     Type                 Name                                           Plan     Info
     pulumi:pulumi:Stack  serverless-aws-react-saas-saasTemplateBackend           1 error
Diagnostics:
  pulumi:pulumi:Stack (serverless-aws-react-saas-saasTemplateBackend):
    error: Running program 'C:\GitHub\SimonHoiberg-Saas-Template\saas-template-main\back-end/' failed with an unhandled exception:
    TSError: ⨯ Unable to compile TypeScript:
    resources/pulumi/resolvers/get-cognito-user/source.ts(12,5): error TS2322: Type '"nodejs21.x"' is not assignable to type '"dotnetcore2.1" | "dotnetcore3.1" | "dotnet6" | "go1.x" | "java8" | "java8.al2" | "java11" | "ruby2.5" | "ruby2.7" | "nodejs10.x" | "nodejs12.x" | "nodejs14.x" | "python2.7" | ... 5 more ... | undefined'.

Solution

  • The package.json file contained this:

    {
      "name": "serverless-aws-react-saas-back-end",
      "devDependencies": {
        "@types/node": "^14"
      },
      "dependencies": {
        "@pulumi/aws": "^6.30.0",
        "@pulumi/awsx": "^2.7.0",
        "@pulumi/pulumi": "^3.0.0"
      }
    }
    

    I changed to this (updated the two pulumi/aws (and awsx) versions):

    {
      "name": "serverless-aws-react-saas-back-end",
      "devDependencies": {
        "@types/node": "^14"
      },
      "dependencies": {
        "@pulumi/aws": "^6.30.0",
        "@pulumi/awsx": "^2.7.0",
        "@pulumi/pulumi": "^3.0.0"
      }
    }
    

    I changed the two strings (in the source code) from:

    runtime: 'nodejs14.x',
    

    to

    runtime: 'nodejs16.x',
    

    (I tried nodejs21.x and it still didn't work, seems like nodejs16.x is highest supported.)

    I ran "npm install" then "pulumi up" and it worked!