DEV Community

Discussion on: How to host a Sapper.js SSR app on Firebase.

 
eckhardtd profile image
Eckhardt • Edited

Hi! No problem.

I just cloned your repo and holy ... is Windows copy and folder deletion a pain... Here's my solution (Also adding to post):

  1. Add some npm packages to help with removing and copying stuff:

npm install -D rimraf mkdirp ncp

The -D flag adds it to dev dependencies, since that's where we need it. Change your scripts to this:

...
"build": "sapper build --legacy && ncp ./__sapper__/build ./functions/__sapper__/build",
"prebuild": "rimraf - functions/__sapper__/build && mkdirp functions/__sapper__/build",
...

I'm afraid there's more.. An error pops up if the firebase-admin dependency in functions/package.json is greater than 7, so just set it to:

"firebase-admin": "^7.0.0"

Remember to:

cd functions && npm install

These solutions are hacky and this post might bite me in the future due to rapid changes in sapper and firebase stuff. But this got it working for me on Windows 10 using your repository. Regards!

Thread Thread
 
jofont profile image
Diogo Fontainhas Garcia Marques • Edited

Ok! So we do have success with your changes!

Some notes:

  1. Couldn't replicate error with firebase-admin version. Working fine with version 8.2.0, actually if I were to set it to 7.0.0, firebase throws an error.

  2. npm start does work but as someone mentioned earlier, I also do not get styles and assets. No issues I think, because you don't really need npm start, just use npm run dev for development and npm run deploy when deploying to Firebase.

  3. Finally, this does indeed look like a very half-arsed way to make Firebase deliver Sapper SSR, because I feel like it's one update from Firebase or one dependency away from breaking (at least on windows). So perhaps either thinking on a more stable way of implementing this or waiting for firebase for a proper Node.js server would be the way. Either way at least for now it works, though I'll probably stick with AWS for production runs.

Thank you very much @eckhardtd for the tutorial! Have a great one!