Search code examples
nuxt.jsvuex

How to import dependency into Vuex actions?


What is the correct way to import functions into Vuex actions? I ask because I get the following eslint error when trying to import a Firebase doc() into my action code:

'doc' is declared but its value is never read.ts(6133)
'doc' is defined but never used.eslintno-unused-vars
(alias) function doc(firestore: FirebaseFirestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData> (+2 overloads)
import doc

Here's the actions.js code:

import { doc } from "firebase/firestore"
import {db} from '~/plugins/firebase.js'

export default {

async getUserProfile({ commit }, authUser) {
  try {
    const docRef = doc(db, 'users', authUser.uid) // <----trying to use `doc()` here but get that eslint error
    ....
   }
....
}

Why can't I import the doc() function into the getUserProfile() action?

Updated with screenshot:

eslint error


Solution

  • In the end, this was caused by the fact that doc was (re)declared later in the code, as noted by the OP in the comments. Hence why ESlint was complaining about unused variable.