Skip to content

context.parserServices is undefined #237

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

Closed
4 tasks done
jewpaltz opened this issue Aug 12, 2024 · 3 comments
Closed
4 tasks done

context.parserServices is undefined #237

jewpaltz opened this issue Aug 12, 2024 · 3 comments

Comments

@jewpaltz
Copy link

jewpaltz commented Aug 12, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I'm using eslint-plugin-vue.
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-vue repo and open the issue in eslint-plugin-vue repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

9.8.0

What version of eslint-plugin-vue and vue-eslint-parser are you using?

What did you do?

Configuration
import withNuxt from './.nuxt/eslint.config.mjs'
import pluginVuetify from 'eslint-plugin-vuetify'
import vueParser from 'vue-eslint-parser'

export default withNuxt([{
    
    files: ['**/*.vue'],
    languageOptions: {
      parser: vueParser,
      ecmaVersion: 2020,
      sourceType: 'module',
      
    },
    plugins: {
      vuetify: {
        rules: pluginVuetify.rules
      }
    },
    rules: {
      ...pluginVuetify.configs.base.rules,
    }
  }]
<template>
    <NuxtLayout>
        <NuxtPage />
    </NuxtLayout>
</template>

What did you expect to happen?

When I run npx eslint . there should be no errors

What actually happened?

I get the error TypeError: Error while loading rule 'vuetify/no-deprecated-classes': Cannot read properties of undefined (reading 'defineTemplateBodyVisitor')
i.e. context.parserServices in each rule is undefined (I threw in a console.log() to verify)
However context.getSourceCode().parserServices does have a proper parserServices object complete with a defineTemplateBodyVisitor etc.

Link to Minimal Reproducible Example

https://github.com/vuetifyjs/eslint-plugin-vuetify

Additional comments

I am attempting to help the vuetify team debug this.
It seems that this was working fine with eslint 8.x and is only and issue with 9.x

context.getSourceCode().parserServices returns the following

{
  program: null,
  emitDecoratorMetadata: false,
  experimentalDecorators: false,
  esTreeNodeToTSNodeMap: WeakMap { <items unknown> },
  tsNodeToESTreeNodeMap: WeakMap { <items unknown> },
  defineTemplateBodyVisitor: [Function: defineTemplateBodyVisitor],
  defineDocumentVisitor: [Function: defineDocumentVisitor],
  defineCustomBlocksVisitor: [Function: defineCustomBlocksVisitor],
  getTemplateBodyTokenStore: [Function: getTemplateBodyTokenStore],
  getDocumentFragment: [Function: getDocumentFragment]
}

But that seems never to be getting injected directly into the context parameter passed to the create function. Which is what the expected behavior seems to be based on https://www.npmjs.com/package/vue-eslint-parser#-usage-for-custom-rules--plugins

@ota-meshi
Copy link
Member

This is an issue with a plugin you are using, please see the migration documentation.

https://eslint.org/docs/latest/use/migrate-to-9.0.0#-removed-multiple-context-methods

@ota-meshi ota-meshi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2024
@jewpaltz
Copy link
Author

Thank you! That is the exact section of the migration documentation that I was looking for!

@javag97
Copy link
Contributor

javag97 commented Mar 31, 2025

I also ran into this as well and wanted to shout out this thread!

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

3 participants