dongwa / vercel-quasar

deploy quasar with ssr mode in vercel
11 stars 0 forks source link

Error: A Serverless Function has exceeded the unzipped maximum size #5

Open Nakroma opened 1 year ago

Nakroma commented 1 year ago

Hey, first of all thanks for making this! I'm currently trying to deploy my quasar project with this, however I get stuck in the build step:

[info] Install dist dependencies took: 2219.621352 ms
[log]  ----------------- Collect artifacts ----------------- 
[info] Collect artifacts took: 20199.524769 ms
Build Completed in /vercel/output [45s]
Deploying outputs...
Error: A Serverless Function has exceeded the unzipped maximum size of 250 MB. : https://vercel.link/serverless-function-size

which is strange, since when I build the project locally with quasar build -m ssr && cd dist/ssr && npm i it comes out at about 80MB. Maybe this is because its installing the entire projects devDependencies in the beginning? But I don't know a lot about the Vercel deploy process.

dongwa commented 1 year ago

Unfortunately, we cannot exceed Vercel's size limit. However, we can reduce the size of our bundles by moving some dependencies from 'dependencies' to 'devDependencies.' When we build server-side rendering (SSR), most of the code from third-party libraries will be added to the build file. Therefore, you can move most of the libraries to 'devDependencies,' and then test locally. If it works, you can proceed with redeployment.

Nakroma commented 1 year ago

@dongwa thats the thing, locally the build plus dependencies is ~80MB, nowhere near the size limit.

dongwa commented 1 year ago

@dongwa thats the thing, locally the build plus dependencies is ~80MB, nowhere near the size limit.

We only use npm i --production during deployment, and I'm not sure why it's causing a 250MB error. I remember the size limit being 50MB, as mentioned in this link: https://github.com/dongwa/vercel-quasar/issues/4. So, I suggest you further reduce the build size, as I mentioned earlier.

dongwa commented 1 year ago

I recommend that you take a look at this article : https://dev.to/patzick/why-dependencies-matter-deploy-your-nuxt-ssr-universal-app-to-vercel-now-4ndp which mentions some methods that are equally applicable to Quasar.

What you need to do is initially modify your src-ssr by not returning the ssrhandler. Instead, set up a Node.js server using 'listen', like:

export async function listen ({ app, port, isReady, ssrHandler }) {
  await isReady()
  return await app.listen(port, () => {
    if (process.env.PROD) {
      console.log('Server listening at port ' + port)
    }
  })
}

then package your project. In the 'dist' directory, gradually remove unused dependencies until you find the smallest dependency list that can run your project. Afterward, revert your changes to src-ssr and attempt a redeployment.