kit icon indicating copy to clipboard operation
kit copied to clipboard

Netlify builds fail when split functions for layout group endpoints are generated

Open Conceptiks opened this issue 3 years ago • 1 comments

Describe the bug

After migrating to the latest svelte version and following this guide to do so, I have noticed that all builds using adapter-netlify fail if the adapter is configured like so:

kit: {
    adapter: adapter({
      edge: false,
      split: true
    })
  }

I must use split as my render function generated by the adapter exceeds the 50MB size limit for Netlify functions. This way, I have come across the following error in the Netlify build log.

Packaging Functions from .netlify/functions-internal directory: 1:07:35 PM: - (layoutgroup)-demo.mjs 1:07:35 PM: - index.mjs


Deploy did not succeed: [PUT /sites/{site_id}/deploys/{deploy_id}][422] updateSiteDeploy default &{Code:422 Message:Incorrect function names. Name should consist of only alphanumeric characters, hyphen & underscores}

This error clearly states that Netlify doesn't support the brackets "()" as characters inside function names. This issue is reproducible, and I have provided a minimal repo to test this out. Note that you must deploy to Netlify to see the build fail.

Reproduction

Minimal repo to reproduce can be found below. Note: You will have to deploy to Netlify to see the error. https://github.com/Conceptiks/netlify-layout-group-bug

Logs

1:07:35 PM: ────────────────────────────────────────────────────────────────
1:07:35 PM:   2. Functions bundling                                         
1:07:35 PM: ────────────────────────────────────────────────────────────────
1:07:35 PM: ​
1:07:35 PM: Packaging Functions from .netlify/functions-internal directory:
1:07:35 PM:  - (layoutgroup)-demo.mjs
1:07:35 PM:  - index.mjs
1:07:35 PM: ​
1:07:36 PM: ​
1:07:36 PM: (Functions bundling completed in 758ms)
1:07:36 PM: ​
1:07:36 PM: ────────────────────────────────────────────────────────────────
1:07:36 PM:   3. Deploy site                                                
1:07:36 PM: ────────────────────────────────────────────────────────────────
1:07:36 PM: ​
1:07:36 PM: Starting to deploy site from 'build'
1:07:36 PM: Creating deploy tree 
1:07:37 PM: ​
1:07:37 PM: ────────────────────────────────────────────────────────────────
1:07:37 PM:   Configuration error                                           
1:07:37 PM: ────────────────────────────────────────────────────────────────
1:07:37 PM: ​
1:07:37 PM:   Error message
1:07:37 PM:   Deploy did not succeed: [PUT /sites/{site_id}/deploys/{deploy_id}][422] updateSiteDeploy default  &{Code:422 Message:Incorrect function names. Name should consist of only alphanumeric characters, hyphen & underscores}
1:07:37 PM: ​
1:07:37 PM:   Resolved config
1:07:37 PM:   build:
1:07:37 PM:     command: npm run build
1:07:37 PM:     commandOrigin: ui
1:07:37 PM:     publish: /opt/build/repo/build
1:07:37 PM:     publishOrigin: ui
1:07:37 PM:   headers:
1:07:37 PM:     - for: /_app/immutable/*
      values:
        cache-control: public, immutable, max-age=31536000
  redirects:
    - from: /
      status: 200
      to: /.netlify/functions/index
    - from: //__data.js
      status: 200
      to: /.netlify/functions/index
    - from: /(layoutgroup)/demo
      status: 200
      to: /.netlify/functions/(layoutgroup)-demo
    - from: /(layoutgroup)/demo/__data.js
      status: 200
      to: /.netlify/functions/(layoutgroup)-demo
1:07:37 PM: Execution cancelled
1:07:37 PM: Error running command: Command was cancelled
1:07:37 PM: Failing build: Failed to build site
1:07:37 PM: Finished processing build request in 16.833005617s

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 (Jammy Jellyfish)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 23.69 GB / 31.28 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.16.0 - /usr/local/bin/node
    npm: 8.11.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.74 
    @sveltejs/adapter-netlify: ^1.0.0-next.77 => 1.0.0-next.77 
    @sveltejs/kit: next => 1.0.0-next.483 
    svelte: ^3.44.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.1

Severity

blocking an upgrade

Additional Information

No response

Conceptiks avatar Sep 15 '22 11:09 Conceptiks

Since this topic is still open: Unfortunately, I have no experience in the development of adapters, otherwise I would be more than happy to assist in creating the PR. Looking around in the repo for the adapter, I think I have identified the correct part of the code where something needs to be changed:

https://github.com/sveltejs/kit/blob/315b64316d8159a58a0b45970f59f58a30cd8a26/packages/adapter-netlify/index.js#L163-L203

The question that I can't answer is how these serverless functions are linked to the inner workings of SvelteKit. I assume that randomly renaming the Netlify functions will result in a broken adapter, although I have not tried this.

Can anyone help here?

Conceptiks avatar Sep 20 '22 09:09 Conceptiks