Netlify deployment with SvelteKit in a GitHub action apparently uses wrong Node.js version

Hi there :wave: ,

I am building a project with SvelteKit, deployed to Netlify. It is hosted on GitHub. The continuous deployment worked fine when I linked the Netlify site to the GitHub repository, as usual. I have just one branch called main for now.

Now I want to run unit tests in a GitHub action and only deploy to Netlify when this action was passing. I googled several ways how that might be achieved. Most of them didn’t work, and after hours of debugging I found that the option of using the Netlify CLI in a separate GitHub action almost works for me. I will add the code below.

For this, I needed to unlink the GitHub repository from the site (since otherwise every commit would trigger a deploy, but of course I only want to trigger a deploy when the commit was pushed and the test was passing; or am I missing something?).

However, many parts of the site now do not work properly. When checking the function logs, I noticed this error:

Feb 1, 12:01:07 PM: 701ef9d6 ERROR TypeError: (intermediate value).isSubsetOf is not a function

Indeed, .isSubsetOf is a method for sets in JavaScript that is quite new, and for this reason I have made sure that everywhere the Node version 22.13.0 is used, also for local development of course. In particular, I have a .nvmrc file that specifies 22.13.0.

But apparently, the deployment triggered in the GitHub action does not use that Node version, even though the logs in GitHub explicitly say so; see also the code below.

I also noticed that, when the GitHub repository was linked to the site, I could add the node version in the site settings (defaults to 18, so I needed to change that). But now, after unlinking, this setting is gone. Maybe Netlify “secretly” still uses Node version 18? I also tried to add the NODE_VERSION environment variable in the Netlfiy UI, but that didn’t fix the issue either. I also still have a file .nvmrc in the project root.

I am also open to other suggestions to achieve what I actually want. For example, I tried to use the official Netlify GitHub action, build hooks (only available when the GitHub repo is linked, so doesn’t make any sense here?), use a new branch called “develop” which is then merged to “main” in a GitHub action when the tests pass and the main branch then triggers Netlify deployment (didn’t work unfortunately, and overcomplicates things imho), change the build command in Netlify to “pnpm test && pnpm build” (produced errors), and find a suitable build plugin.

Actually, I have been wondering why Netlify doesn’t support this “run tests first, then deploy” out of the box. I also read related topics here in the forum but they didn’t solve my issue. Some of the solutions also apparently only work for static states.


Code of the GitHub action “deploy.yml”.

name: deploy

on:
    workflow_run:
        branches:
            - main
        workflows: ['test']
        types:
            - completed

jobs:
    deploy:
        if: ${{ github.event.workflow_run.conclusion == 'success' }}
        runs-on: ubuntu-latest

        strategy:
            matrix:
                node-version: [22.13.0]

        steps:
            - uses: actions/checkout@v4

            - name: Install pnpm
              uses: pnpm/action-setup@v4
              with:
                  version: 10

            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v4
              with:
                  node-version: ${{ matrix.node-version }}
                  cache: 'pnpm'

            - name: Install Netlify CLI
              run: pnpm install netlify-cli@18.0.3 -g

            - name: Install Dependencies
              run: pnpm i

            - name: Sync SvelteKit
              run: pnpm svelte-kit sync

            - name: build project
              run: pnpm build

            - name: Deploy to Netlify
              id: netlify_deploy
              run: |
                  netlify deploy \
                    --dir build \
                    --site ${{ secrets.NETLIFY_SITE_ID }} \
                    --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \
                    --message "Deploy from GitHub Action" \
                    --prod

Of course, I have added the two secrets to the repository’s settings. As mentioned, this workflow runs as expected. It doesn’t produce any errors while it is running, neither on GitHub nor on Netlify. But the site doesn’t work after the deployment since apparently a wrong Node.js version is used (I cannot exclude other mistakes on my side, though).

PS:

Meanwhile, I also added a log console.log(process.version) in a server file which confirmed my guess of the root cause. It is indeed logging version 18.

Set an environment variable with the name AWS_LAMBDA_JS_RUNTIME and value nodejs22.x and redeploy.

1 Like

Awesome! Thank you very much. When I set the environment variable in the Netlify UI of the page, this will solve the problem. Meanwhile, I also added a log console.log(process.version) which confirmed my guess of the root cause.

Is there a way to update the GitHub action and set that environment variable? (It would be nice to have this setting in the repository.) I tried the following:

            - name: Set the correct Node.js version for Netlify functions
              run: netlify env:set AWS_LAMBDA_JS_RUNTIME "nodejs22.x"

But this does not work since in that context the netlify CLI is not connected to any site. I also don’t know if the netlify deploy command supports to set custom environment variables.

I think the netlify toml will not work since that requires the GitHub repository to be linked to the site?

If you have environment variables with the name NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID, the CLI automatically reads those, so you should not have to explicitly link the site or pass any flags.

Yes, I understood that.

When I set the AWS_LAMBDA_JS_RUNTIME = nodejs22.x variable in the Netlify UI, it works.

But I was wondering if I can set this variable in my repository. Just to make this required setting more visible. (For now, I added a comment in my deploy.yml.)

No. You need to either manually set it in the UI or use the CLI like you did to set the variable via Netlify API.

1 Like