Upgrade to Vite 2.7+ causes Runtime.UserCodeSyntaxError on Netlify-hosted SvelteKit

I can’t seem to reproduce this locally so I thought I’d reach out here, perhaps for some help with locating the root of the problem.

I am working on a SvelteKit site hosted on Netlify – (eloquent-euclid-d54e46) – and have recently updated my dependencies. Updating Vite to 2.7.1 causes the site to break completely, returning:

{
  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Unexpected token '.'",
  "trace": [
    "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '.'",
    "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
    "    at Module.load (internal/modules/cjs/loader.js:863:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
    "    at internal/main/run_main_module.js:17:47"
  ]
}

Previous posts with similar errors seem to indicate that this is generally an issue with Netlify’s version of NodeJs having trouble with the syntax used, but I’ve manually set the version to lts (16.13.1) and have no issue spinning up a dev instance locally with the same Node version. I’ve had a look at the generated code from a local build and there’s nothing that seems to be in error, but the above error doesn’t give me enough information to know where to look (or maybe I’m not reading the stack trace right).

Any ideas where I could look or what I could try to narrow down the issue?

Thanks!

Functions need a different variable for Nodejs version (however, from Monday, 13th Dec, this is going to be default).

Check this out:

So just to be clear, any Netlify functions that are running ignore the .node-version file in the root? The file is only used for building?

That is correct @james-camilleri. As specified in the linked documentation, you need to set the AWS_LAMBDA_JS_RUNTIME environment variable to change the node version used for functions.

I see, thank you. :slight_smile:

Did this solve your issue? I’m having the same problem for a site I made with sveltekit as well, but setting the environment variable didn’t fix my issue.

It did actually, as of the 13th December it kicked in automatically so I didn’t even need to set the ENV variable.

1 Like