DEV Community

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

Collapse
 
jofont profile image
Diogo Fontainhas Garcia Marques

Trying to get this to work but I'm getting stuck in the editing the npm scripts.
First, i'm assuming we need to edit the npm scripts from sapper (so not the package.json from inside functions), secondly, when I edit the scripts, the prebuid doesn't run, there are two errors; the first says that rm is not a valid command (fair enough, changed to del) then it didn't like the mkdir -p so I removed the -p. At the end it still doesn't run and says Invalid switch - "__sapper__"., Any idea why? Thank you for the article anyway!

Collapse
 
eckhardtd profile image
Eckhardt

Hi!

It would really be easier for me if I can get a link to a github repo and explore myself so I can give a complete answer.

I’d like to update this post if there were any changes to the workflow because of updates etc.

Also what OS are you running? I haven’t tested this on all platforms. You would be a huge help here!

Thanks.

Collapse
 
jofont profile image
Diogo Fontainhas Garcia Marques

Hello!
Sorry for the delay. So here you go: gitlab.com/JoFont/sapper-firebase-...

The repo has a Readme with the same info I wrote in the first comment along with some images.

I'm running Windows 10. Thank you very much for you help, and have a great day!

Thread Thread
 
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!