An error occurred when deploying a development using Laravel on the back end and Nuxtjs on the front end. I was able to develop without problems when developing in the local environment, but an error occurred during deployment.
netlify deploy log
6:23:49 PM: 1. Build command from Netlify app
6:23:49 PM: ────────────────────────────────────────────────────────────────
6:23:49 PM:
6:23:49 PM: $ npm run generate
6:23:49 PM: > xxx_frontend@1.0.0 generate /opt/build/repo
6:23:49 PM: > nuxt generate
6:23:50 PM: [warn] When using `nuxt generate`, you should set `target: 'static'` in your `nuxt.config`
6:23:50 PM: 👉 Learn more about it on https://go.nuxtjs.dev/static-target
6:24:03 PM: [error] [BABEL] Note: The code generator has deoptimised the styling of /opt/build/repo/node_modules/bootstrap-vue/src/icons/icons.js as it exceeds the max of 500KB.
6:24:24 PM: [error] /loginBtn
6:24:24 PM:
6:24:24 PM: TypeError: Cannot read property 'headers' of undefined
6:24:24 PM: at Store.nuxtServerInit (store/index.js:53:0)
6:24:24 PM: at Array.wrappedActionHandler (/opt/build/repo/node_modules/vuex/dist/vuex.common.js:853:23)
6:24:24 PM: at Store.dispatch (/opt/build/repo/node_modules/vuex/dist/vuex.common.js:518:15)
6:24:24 PM: at Store.boundDispatch [as dispatch] (/opt/build/repo/node_modules/vuex/dist/vuex.common.js:408:21)
6:24:24 PM: at module.exports.__webpack_exports__.default (.nuxt/server.js:131:0)
6:24:24 PM: at runNextTicks (internal/process/task_queues.js:62:5)
6:24:24 PM: at listOnTimeout (internal/timers.js:518:9)
6:24:24 PM: at processTimers (internal/timers.js:492:7)
nuxt code The source code below is the code to get the user information every time the page is loaded.
- Get the token of the cookie and request it as headers information.
- Save the value returned from the backend as user information.
export const actions = {
async nuxtServerInit({ commit },{ req }){
const token = 'Bearer ' + cookieparser.parse(req.headers.cookie).token
let user = '';
try {
user = await this.$axios.$get('/user',{
headers:{
'Authorization': token,
'Accept':'application/json'
}
})
} catch (err) {
console.log(err);
}
commit('setToken',{ token:cookieparser.parse(req.headers.cookie).token});
commit('setUser',user);
}
}