Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt app crashes when files are edited during npm run dev #51

Open
marcvangend opened this issue Feb 1, 2019 · 3 comments
Open

Nuxt app crashes when files are edited during npm run dev #51

marcvangend opened this issue Feb 1, 2019 · 3 comments

Comments

@marcvangend
Copy link

While npm run dev was running, I tried to change a component file. Even the most trivial change, such as indenting a line of code, resulted in a crash. The error message on the command line:

✖ error TypeError: Cannot read property 'data' of undefined
  at exports.modules../lib/jsonApiClient.js.axios__WEBPACK_IMPORTED_MODULE_1___default.a.interceptors.response.use.response (pages/recipes/index.js:900:83)
  at process._tickCallback (internal/process/next_tick.js:68:7)

I have been looking into this with support from @yann-yinn (thank you!) and finally found this workaround:

import qs from 'qs';

 // Add a response interceptor to format response with jsonapi-parse
 axios.interceptors.response.use(response => {
-  return jsonapiParse.parse(response.data).data;
+  const parsedResponse = jsonapiParse.parse(response.data);
+  if (parsedResponse === undefined) {
+    return response;
+  }
+  return parsedResponse.data;
 });

 export default {

What I think is happening: The response object that is passed to this interceptor when the first request is made, is indeed a proper response object that contains response.data and can be parsed by jsonapiParse.parse(). However, when a file is edited and the app is rebuilt, it seems that the parsed result (which was cached somewhere?) passes through this interceptor again.

While this workaround stops the crashing, it's ugly and it shouldn't be there. I guess we should be looking for a way to either pass the original, raw response to the interceptor again, or else avoid calling the interceptor again when the app is rebuilt with cached data. I'm willing to help fix this, but I could use some help in understanding how the app works and finding out where this data comes from.

Additional info about my setup:
contenta_vue_nuxt 2.0.1, with under the hood nuxt 2.2.0 and axios 0.18.0
node v10.14.2 with npm v6.4.1
backend: contenta_jsonapi dev-8.x-3.x, installed using contenta-jsonapi-project dev-8.x-2.x

@ludo1960
Copy link

Hello,
You seem to be a bit further down the road on this project than me. I'm hoping you can throw a few clues my way. What did you put in your serverFilesUrl configuration? I put http:mysite.com/api/files and get the error:TypeError Cannot read property 'data' of undefined. I too would like to find out what makes this app tick. Perhaps we can pool resources?

@yann-yinn
Copy link
Contributor

Yep sorry guys i moved on other things, as i wrote in the README and i can't help you. Should we archive this project to avoid frustration ? cc @e0ipso

@e0ipso
Copy link
Member

e0ipso commented May 17, 2019

I think it's fine to leave it there for inspiration @yann-yinn.

marcvangend added a commit to marcvangend/contenta_vue_nuxt that referenced this issue Oct 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants