thgh / vercel-sapper

Vercel builder for Sapper with SSR enabled
MIT License
189 stars 25 forks source link

Error: The Serverless Function "index" is 60mb which exceeds the maximum size limit of 50mb #36

Closed jamiekieranmartin closed 4 years ago

jamiekieranmartin commented 4 years ago

I've been getting this issue below when deploying to vercel.

Error: The Serverless Function "index" is 60mb which exceeds the maximum size limit of 50mb. Learn more: https://vercel.com/docs/v2/platform/limits#serverless-function-size

Seems my static folder is more than 50mb. What's strange though is I have NextJS applications with at least 1GB of data. Is this meant to happen? Is is a shortcoming of vercel-sapper in that it's actually a serverless function run on vercel? What do?

vercel.json { "version": 2, "builds": [{ "src": "package.json", "use": "vercel-sapper" }] }

thgh commented 4 years ago

Static files are indeed included twice: once static to be hosted on CDN, once in the lambda: https://github.com/thgh/vercel-sapper/blob/d2a5a50c9e79aa7cdf164a94bbce294a4f674a1b/index.js#L53

There could be an option to not include static files in the lambda, maybe using an include filter.

antony commented 4 years ago

I'd be in favour of not including static files in the lambda ever. Rollup provides good support for importing images where required, so there's no good reason I can think of for them to be in the function.

thgh commented 4 years ago

OK makes sense to not include the static files. I have some projects that read files from the static folder however. Probably not good enough of a reason to include static files in all lambdas 😄 According to the principle of least surprise, one would expect the files to be accessible so if it's possible to include them by configuration, that would be great.

thgh commented 4 years ago

@JamieKieranMartin do you mind checking out vercel-sapper@rc ?

It should work without extra config.

jamiekieranmartin commented 4 years ago

@thgh seems it doesn't like the globAndPrefix?

Retrieving list of deployment files... 17:45:49.223 Downloading 28 deployment files... 17:45:51.948 Installing build runtime... 17:45:53.639 Build runtime installed: 1691.076ms 17:45:53.926 /vercel/5cf5948fca0ea9db/.build-utils/.builder/node_modules/vercel-sapper/index.js:50 17:45:53.926 ...(await globAndPrefix(entrypointDir, path)) 17:45:53.926 ^^^^^^^^^^^^^ 17:45:53.926 SyntaxError: Unexpected identifier 17:45:53.926 at wrapSafe (internal/modules/cjs/loader.js:1070:16) 17:45:53.927 at Module._compile (internal/modules/cjs/loader.js:1120:27) 17:45:53.927 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10) 17:45:53.927 at Module.load (internal/modules/cjs/loader.js:1000:32) 17:45:53.927 at Function.Module._load (internal/modules/cjs/loader.js:899:14) 17:45:53.927 at Module.require (internal/modules/cjs/loader.js:1042:19) 17:45:53.927 at require (internal/modules/cjs/helpers.js:77:18) 17:45:53.927 at requireBuilder (/var/task/sandbox-worker.js:20228:14) 17:45:53.927 at installToolsStep2 (/var/task/sandbox-worker.js:20332:15) 17:45:53.927 at mainSub (/var/task/sandbox-worker.js:20123:33)

jamiekieranmartin commented 4 years ago

https://github.com/JamieKieranMartin/now-sapper-demo

The repo I'm currently replicating the issue with. Now the CLI doesn't seem to like the "config" in vercel.json

Error! The propertyconfig:is not allowed in vercel.json – please remove it.

What I've done for the mean time is deploy a static vercel/serve to serve files. I'm assuming this is more so best practice?

jamiekieranmartin commented 4 years ago

@thgh

Ok so vercel.json

{ "version": 2, "builds": [ { "src": "package.json", "use": "vercel-sapper@rc" } ] }

gets you the above error.

Adding the "config" in the vercel.json, errors on the vercel CLI.

Error! The property 'config:' is not allowed in vercel.json – please remove it.

{ "version": 2, "builds": [ { "src": "package.json", "use": "vercel-sapper@rc", "config:": { "include": ["static"] } } ] }

jamiekieranmartin commented 4 years ago

@antony

I'm compiling tailwind css in the static when I push which is why I'd still favour the static folder, as that can get built before it serves it on vercel. Beforehand I did have added images to use for the site, but I'm assuming it'd be better to offload those to the CDN, not the lambda?

I had originally thought that the static would get pushed to the CDN and not be bundled with the lambda. Which is I'm assuming what NextJS does, as I never came across this problem using it

thgh commented 4 years ago

Woops, made an async await mistake, it should work now (on vercel-sapper@rc) without config.

jamiekieranmartin commented 4 years ago

@thgh

That works! Files served statically and no +50mb issue. Cheers!

jamiekieranmartin commented 4 years ago

@thgh

One thing to note, in local development the files aren't served by sapper so the user would need to serve them by some other means. Production on vercel is fine however.

To combat this issue, depending on the process.env.NODE_ENV, I'm inserting sirv into my sapper middleware for "development". Not ideal, but seems to work just fine.

thgh commented 4 years ago

Can you always enable sirv or does it error because the static folder is missing?

jamiekieranmartin commented 4 years ago

image

Yeah, as soon as I add sirv to production, vercel has issues.

thgh commented 4 years ago

I updated @rc to add the first file in the static folder in case there are 0 static files included. If the sirv fix is needed, it will log in the build which file was included: 12:13:33.108 vercel-sapper includeFiles [ 'static/favicon.png' ]

By the way, I tried to use config and it seemed to work: (you had a typo: "config:":)

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "vercel-sapper@rc",
      "config": { "include": ["static"] }
    }
  ]
}
jamiekieranmartin commented 4 years ago

Oh lol 🤦‍♂️

I'll test it and get back to you

jamiekieranmartin commented 4 years ago

@thgh works nicely! sirv doesn't have any issues now. One issue I had was the 50mb.zip file in that test repo was the first file in static, so it failed on that build. Not sure if it'd be confusing for other users with no context. Unless it's just clearly documented somewhere?

thgh commented 4 years ago

I wanted to create an empty file static/keep-static-${randomString}.txt but I'm not sure how FileBlob vs FileFsRef works, so that will be for another time.

jamiekieranmartin commented 4 years ago

Yeah, that's cool. We've solved the main problem at least