nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

$http is undefined in async asyncData method in production (nuxt build && nuxt start) #73

Closed acrolink closed 5 years ago

acrolink commented 5 years ago

Version

v0.3.5

Reproduction link

https://jsfiddle.net/yqr9s70a/

Steps to reproduce

The following code works perfect in development (nuxt script):

  async asyncData({ $http }) {
    let response = await $axios.get(`/api/items`)
    return { entities: response.data.data }
  }

However, in production (nuxt build && nuxt start) I get this error:

ERROR Cannot read property '$get' of undefined 07:59:22

  at asyncData (df028d49c11282eafe57.js:1:0)
  at C (server.js:1:0)
  at Promise.all.h.map.n (server.js:1:0)
  at Array.map (<anonymous>)
  at e.default (server.js:1:0)

What is expected ?

To work in production as it does on development

What is actually happening?

Error

acrolink commented 5 years ago

The issue was caused because I used a custom nuxt.config.js for production with the name nuxt.config.prod.js.

On build I was not using the -c nuxt.config.prod.js switch. This switch must be declared on both tasks nuxt build and nuxt start

Works as expected.