简体   繁体   中英

How to enable Vuex in Firebase Functions when deploying Nuxt app

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:

在此处输入图像描述

And this is the structure of nuxt folder inside functions:

在此处输入图像描述

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM