question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot match against 'undefined' or 'null'.

See original GitHub issue

Hi,

I try to create an API module which will be used by other modules in my store to ask for data then apply my business logic on top of it. Here is my api.js file:

import Vue from 'vue'
import { createStore, Resource } from 'vuex-rest-api'

const options = {
  axios: Vue.axios
}
const resource = new Resource(__API_ROOT__, options)

// Auth (User and Guest cases)
resource
  .addAction({
    action: "login",
    method: "post",
    property: "token",
    pathFn: () => '/auth/login'
  })
  .addAction({
    action: "getGuestHash",
    method: "get",
    property: "guest_hash",
    pathFn: () => '/auth/get_guest_hash'
  })
// Cart
  .addAction({
    action: "getCart",
    method: "get",
    property: "cart",
    pathFn: (id) => `/carts/${id}`
  })
  .addAction({
    action: "createCart",
    method: "post",
    property: "cart",
    pathFn: () => `/carts`
  })
  .addAction({
    action: "cleanCart",
    method: "put",
    property: "cart",
    pathFn: () => `/carts/clean`
  })
  .addAction({
    action: "getActiveCart",
    method: "get",
    property: "activeCart",
    pathFn: () => `/carts/active`
  })
  .addAction({
    action: "changeDomiciliationOffer",
    method: "put",
    property: "cart",
    pathFn: (id) => `/carts/${id}`
  })
  .addAction({
    action: "addOffer",
    property: "cart",

  })

export default createStore(resource)

my store/index.js file:

import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './actions'
import getters from './getters'
import api from './modules/api'

Vue.use(Vuex)

const state = {
  count: 0
}

const store = new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
  modules: {
    api
  }
})

export default store

Here is the error I get from the console: capture d ecran 2017-05-10 a 15 13 03

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
christianmalekcommented, May 11, 2017

@sotaan I just saw another error in your code snippet. You have to destructure the params in the path fn. False:

pathFn: (id) => `/carts/${id}` // false (id is the params object and not the id property

Correct:

pathFn: ({id}) => `/carts/${id}`
1reaction
sotaancommented, May 10, 2017

I just found that I needed to call my actions that way: this.store.$dispatch('myaction', {}) to get it working. Calling that way: this.store.$dispatch('myaction') will trigger the error. I suggest that it must come from destructing assignment in your params in here: storeCreator.ts

try that: storeActions[dispatchString] = async ({ commit }, { params = {}, data = {} } = {}: ActionParamsBody) => { ...

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot match against 'undefined' or 'null'
this error should only arise if the array or object being destructured or its children is undefined or null . Exactly. In your...
Read more >
Uncaught TypeError: Cannot match against 'undefined' or 'null'.
At C:\Users\morta\AppData\Local\atom\app-1.23.3\resources\app\src\tokenized-buffer.js:517 TypeError: Cannot match against 'undefined' or 'null'. at ...
Read more >
Getting to Grips with ES6: Destructuring - Medium
ES6 destructuring allows us to achieve the same result with a much more concise syntax. ... Uncaught TypeError: Cannot match against 'undefined' or...
Read more >
Uncaught TypeError: Cannot match against 'undefined' or 'null'.
Uncaught TypeError : Cannot match against 'undefined' or 'null'.
Read more >
Cannot destructure Property of Undefined Error in JS
The "Cannot destructure property of undefined" error occurs when we try to destructure a property from a value that is equal to `undefined`....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found