andrasbacsai / sapper-tailwind-starter

Sapper + Tailwind example project
5 stars 3 forks source link

process is not defined #1

Closed Catsvilles closed 3 years ago

Catsvilles commented 3 years ago

Hey, I'm trying to redesign my production Sappe app to Tailwind and need of a use of process in my comoponents, but for some reason I'm getting this error while with other starters I don't. Any idea what I messed up or need to setup? Thanks :)

andrasbacsai commented 3 years ago

Hey, the process object could only available on the server-side. If you need to access some environment variable, you need to populate it through the sapper.middleware in server.js:

sapper.middleware({
 session: (req, res) => ({
  home: process.env.HOME
 })
})

Then you can access it on the client-side with:

<script>
 import { stores } from '@sapper/app';
 const { session } = stores();
 console.log($session.home)
</script>

I hope it helps.

Catsvilles commented 3 years ago

Hey, thanks for getting back to me! There are so many reasons for this error actually, somehow I fixed it (not really sure how), after that I got many other errors but I guess I just have to pull through, Sapper is really unstable framework and every starter templates has it's own unique stuff we have to consider :)

andrasbacsai commented 3 years ago

Let's wait for SvelteKit! (I'm excited)