Generating images using Packer. Getting Error for Nodejs

I am using packer to generate images in Azure DevOps. This is the github source that I am using: https://github.com/actions/runner-images.
I am using Ubuntu-20.04 and am at the release ubuntu20/20240603. However, when I deploy the pipeline, I am repetedly getting the following error by Nodejs part:

this is the command that I am using to buil image:

this is my install-nodejs.sh script where Nodejs is installed:

sudo packer build --force -on-error=cleanup -var "client_id=$(VAR_CLIENT_ID)" -var "client_secret=$CLIENTSECRET" -var "template_dir=$template_dir" -var "sources_dir=$SOURCES_DIR" -var "sig_image_version=$(IMAGE_VERSION)" "$template_dir/packer/azure_devops_agent_basic/ubuntu2004.pkr.hcl"
# Source the helpers for use with the script
source $HELPER_SCRIPTS/install.sh

# Install default Node.js
default_version=$(get_toolset_value '.node.default')
curl -fsSL https://raw.githubusercontent.com/tj/n/master/bin/n -o ~/n
bash ~/n $default_version

# Install node modules
node_modules=$(get_toolset_value '.node_modules[].name')
npm install -g $node_modules

echo "Creating the symlink for [now] command to vercel CLI"
ln -s /usr/local/bin/vercel /usr/local/bin/now

# fix global modules installation as regular user
# related issue https://github.com/actions/runner-images/issues/3727
sudo chmod -R 777 /usr/local/lib/node_modules
sudo chmod -R 777 /usr/local/bin

rm -rf ~/n

invoke_tests "Node" "Node.js"

This is my Node.Test.ps1 script:

Describe "Node.js" {
    $binaries = @("node")
    $module_commands = if ((Get-ToolsetContent).node_modules) {
        (Get-ToolsetContent).node_modules | ForEach-Object { $_.command }
    }
    else {
        @()
    }
    $testCases = $binaries + $module_commands | ForEach-Object { @{NodeCommand = $_ } }

    It "<NodeCommand>" -TestCases $testCases {
        "$NodeCommand --version" | Should -ReturnZeroExitCode
    }

    It "Node.js version should correspond to the version in the toolset" {
        node --version | Should -BeLike "v$((Get-ToolsetContent).node.default).*"
    }
}

My toolset.json script code block where modules are defined:

"node": {
        "default": "18",
        "node_modules": [
            {
                "name": "yarn",
                "command": "yarn"
            }
        ]
    },

and this is Toolset.Tests.ps1 script for tests:

Describe "Toolset" {
    $tools = (Get-ToolsetContent).toolcache

    $toolsExecutables = @{
        Python = @{
            tools   = @("python", "bin/pip")
            command = "--version"
        }
        node   = @{
            tools   = @("bin/node", "bin/npm")
            command = "--version"
        }
        PyPy   = @{
            tools   = @("bin/python", "bin/pip")
            command = "--version"
        }
        go     = @{
            tools   = @("bin/go")
            command = "version"
        }
        Ruby   = @{
            tools   = @("bin/ruby")
            command = "--version"
        }
        CodeQL = @{
            tools   = @("codeql/codeql")
            command = "version"
        }
    }

    foreach ($tool in $tools) {
        $toolName = $tool.Name
        Context "$toolName" {
            $toolExecs = $toolsExecutables[$toolName]

            foreach ($version in $tool.versions) {
                # Add wildcard if missing
                if ($version.Split(".").Length -lt 3) {
                    $version += ".*"
                }

                $expectedVersionPath = Join-Path $env:AGENT_TOOLSDIRECTORY $toolName $version

                It "$version version folder exists" -TestCases @{ ExpectedVersionPath = $expectedVersionPath } {
                    $ExpectedVersionPath | Should -Exist
                }

                $foundVersion = Get-Item $expectedVersionPath `
                | Sort-Object -Property { [SemVer]$_.name } -Descending `
                | Select-Object -First 1
                $foundVersionPath = Join-Path $foundVersion $tool.arch

                if ($toolExecs) {
                    foreach ($executable in $toolExecs["tools"]) {
                        $executablePath = Join-Path $foundVersionPath $executable

                        It "Validate $executable" -TestCases @{ExecutablePath = $executablePath } {
                            $ExecutablePath | Should -Exist
                        }
                    }
                }
            }
        }
    }
}

I had also edited the Node.Tests.ps1 script inorder for it to not show an error if iterating null and also added the yarn module even though I dont need it.

I know this is a very specific and complicated problem but I am not able to find any solution for this. Would be nice if someonw know how to solve it or give pointers :’)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật