How to enable Vuex in Firebase Functions when deploying Nuxt app

211 Views Asked by At

I'm trying to deploy a Nuxt SSR app to Firebase Functions to be served from the client and server side, everything works as expected but when trying to implement @nuxtjs/auth it works locally but not when deployed to Firebase, looking into the Firebase Functions console it says:

FATAL Enable vuex store by creating store/index.js.

In my store folder I have several files for vuex spaces, I've created the index.js file there and tried with and without content but result is the same.

What I do before deploying the functions is to copy the generated .nuxt folder into functions folder:

npm run build && rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.js functions/

After that, this is the functions folder structure:

enter image description here

And this is the structure of nuxt folder inside functions:

enter image description here

As you can see inside the nuxt folder there is not a store folder, just a store.js file, reading it I've found it says:

store = normalizeRoot(require('../store/index.js'), 'store/index.js')

But store folder is two folders back, in the root folder, so I've changed it to:

store = normalizeRoot(require('../../store/index.js'), 'store/index.js')

And tried to deploy functions manually, but result is the same error message.

I don't know what to do to enable Vuex in the server side of Firebase functions, I think that by changing the store.js file I could solve it, but I would need to change it in every deployment. What is the correct way to solve it? Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

By the moment I've solved it by copying my store/ folder into functions/ folder, now the Firebase Functions console says nothing and it looks like work, but I'm not sure if it is the correct way to solve it.

I've changed my predeploy command to look like this:

rm -rf functions/nuxt && cp -r .nuxt/ functions/nuxt/ && cp nuxt.config.js functions/ && cp -r store/ functions/