Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Sveltekit project throws unhandled error on Netlify #5445

Closed
Kevinmatthews100 opened this issue Jul 9, 2022 · 6 comments
Closed

New Sveltekit project throws unhandled error on Netlify #5445

Kevinmatthews100 opened this issue Jul 9, 2022 · 6 comments

Comments

@Kevinmatthews100
Copy link

Kevinmatthews100 commented Jul 9, 2022

Describe the bug

After creating a new Sveltekit project with npm create svelte my-app and deploying to Netlify, the site will build successfully, but Runtime.UserCodeSyntaxError - SyntaxError: Unexpected token '??=' will be thrown upon visiting the site.

Reproduction

Example repository

Github: https://github.com/Kevinmatthews100/sveltekit-netlify-issue-reproduction
Netlify deployment of above repository: https://quiet-selkie-61acce.netlify.app

Steps to reproduce

Create a new sveltekit project

npm create svelte my-app

Choose the following options as prompted

Which Svelte app template? > Skeleton project
Add type checking with TypeScript? > No
Add ESLint for code linting? > No
Add Prettier for code formatting? > No
Add Playwright for browser testing? > No

CD to your new project, and add netlify.toml to the root of your project with the following contents:

[build]
  command = "npm run build"
  publish = "build"

To ensure Netlify builds with Node version 16, add .nvmrc to the root of your project with the following contents:

v16

Optionally, resolve npm dependences and ensure your project can successfully start and build locally

npm install

# Expect a dev server to start successfully
npm run dev

# Expect the project to build successfully
npm run build

Next, initialize a git repository for the project, create a new Github repository, and push your newly created Sveltekit project.

Deploy the project to netlify

Create a new site on netlify, importing the github repo you created

Upon visiting the deployed site, you should see that an unhandeled error is thrown with the message:

Runtime.UserCodeSyntaxError - SyntaxError: Unexpected token '??='

Logs

This function has crashed

An unhandled error in the function code triggered the following message:
Runtime.UserCodeSyntaxError - SyntaxError: Unexpected token '??='

Stack trace
Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '??='
    at _loadUserApp (/var/runtime/UserFunction.js:218:13)
    at Object.module.exports.load (/var/runtime/UserFunction.js:279:17)
    at Object.<anonymous> (/var/runtime/index.js:43:34)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47

Connection details
Netlify internal ID: 01G7HRHY8REBNRFDWXYNAGR6PE

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 289.06 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.2.0 - ~/.nvm/versions/node/v18.2.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.9.0 - ~/.nvm/versions/node/v18.2.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Safari: 15.3
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.55
    @sveltejs/kit: next => 1.0.0-next.367
    svelte: ^3.44.0 => 3.49.0
    vite: ^2.9.13 => 2.9.14

Severity

serious, but I can work around it

Additional Information

The same error will occur when configuring the project with the most recent version of @sveltejs/adapter-netlify, which is 1.0.0-next.67 at the time of writing, and following the installation instructions here.

The issue can be worked around by installing and pinning @sveltejs/adapter-netlify to 1.0.0-next.65.

1.0.0-next.66 causes the same build error detailed in issue #5337.

@Kevinmatthews100 Kevinmatthews100 changed the title New Sveltekit projects throw unhandled error on Netlify New Sveltekit project throws unhandled error on Netlify Jul 9, 2022
@gtm-nayan
Copy link
Contributor

5319? Are you sure you got the right one?

Also, could you see if setting the AWS_LAMBDA_JS_RUNTIME environment variable on netlify to nodejs16.x and doing a new deploy fixes it?

@Kevinmatthews100
Copy link
Author

Kevinmatthews100 commented Jul 9, 2022

5319? Are you sure you got the right one?

Also, could you see if setting the AWS_LAMBDA_JS_RUNTIME environment variable on netlify to nodejs16.x and doing a new deploy fixes it?

Apologies, #5337 was the correct issue.

Setting AWS_LAMBDA_JS_RUNTIME to nodejs16.x fixes the deploy.

Is this something that will be resolved when Netlify begins defaulting to Node 16 on Monday? With the .nvmrc file in my project as detailed above, Netlify was building the project with node v16.16.0, but presumably the lambda runtime is not using that version.

@rmunn
Copy link
Contributor

rmunn commented Jul 10, 2022

The changelog entry for 1.0.0-next361 says that it contains a breaking change: Kit now requires Node 16.9 or later. So yes, this will probably auto-resolve when Netlify defaults to Node 16.

@Bradley-H
Copy link

@rmunn If i'm understanding this correctly, I need to just update my nodeRC with node16+

@ascorbic
Copy link
Contributor

FYI, as of today the default Lambda JS runtime on Netlify is nodejs16.x, so this should work out of the box.

@Kevinmatthews100
Copy link
Author

Kevinmatthews100 commented Jul 11, 2022

I just reran the deployment of the example repository without explicitly setting AWS_LAMBDA_JS_RUNTIME, and it looks like we're good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants