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

Parsing error: Cannot set property index of Error which has only a getter #2304

Closed
2 tasks done
messenjer opened this issue Oct 27, 2023 · 4 comments
Closed
2 tasks done
Labels
feat: typescript needs repro Need a repository that can reproduce the problem, or a link to DEMO.

Comments

@messenjer
Copy link

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 8.52.0
  • eslint-plugin-vue version: 9.18.0
  • Node version: 18
  • Operating System: Apple

Please show your full configuration:

/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
  root: true,
  extends: [
    'plugin:vue/vue3-recommended',
    'eslint:recommended',
    '@vue/eslint-config-typescript',
    '@vue/eslint-config-prettier/skip-formatting'
  ],
  overrides: [
    {
      files: ['cypress/e2e/**/*.{cy,spec}.{js,ts,jsx,tsx}'],
      extends: ['plugin:cypress/recommended']
    }
  ],
  rules: {
    'no-unused-vars': ['error', { varsIgnorePattern: '^_', argsIgnorePattern: '^_' }],
    '@typescript-eslint/no-unused-vars': [
      'error',
      { varsIgnorePattern: '^_', argsIgnorePattern: '^_' }
    ],
    'vue/no-v-html': 'off',
    'vue/multi-word-component-names': 'off',
    'vue/no-setup-props-destructure': 'off'
  },
  parserOptions: {
    ecmaVersion: 'latest'
  }
};

What did you do?

<script setup lang="ts">
import { ref } from 'vue';

const test = ref(<{ param: string; param2: string }>{ param: 'test', param2: 'test2' });
</script>

The code above is wrong. In the original code the type definition and the object instantiation are mixed together within the ref function call.

-const test = ref(<{ param: string; param2: string }>{ param: 'test', param2: 'test2' });
+const test = ref<{ param: string; param2: string }>({ param: 'test', param2: 'test2' });

The error message is :

0:0 Parsing error: Cannot set property index of Error which has only a gettereslint

What did you expect to happen?

A better message, with the problematic line.

Or simply find this issue by doing a google search with this error message. To understand that there is a syntax error in the code.

What actually happened?

[{
	"resource": "src/components/HelloWorld.vue",
	"owner": "eslint",
	"severity": 8,
	"message": "Parsing error: Cannot set property index of Error which has only a getter",
	"source": "eslint",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 1
}]

Repository to reproduce this issue

❗ If you don't share it for a few days, we silently close this issue.

@ota-meshi ota-meshi added the needs repro Need a repository that can reproduce the problem, or a link to DEMO. label Oct 27, 2023
@remiconnesson
Copy link

I get the same error but I don't know why. The code is able to run without crashing but I get this error in the linter.

I don't know the source.

@remiconnesson
Copy link

I get the same error but I don't know why. The code is able to run without crashing but I get this error in the linter.

I don't know the source.

Found the line by commenting everything and uncomment bit by bit until I find it.

const takeEnds = <T>(a: T[]): T[] => [a[0], a[a.length - 1]]

@FloEdelmann
Copy link
Member

Reproduction: https://ota-meshi.github.io/eslint-plugin-vue-demo/#eJw9jsEKwyAQRH9l2YstFAo5JsYv8SLWBKGusm56Ef+9SUNzGXjwZpiGPr8Cjqir51gEapCtwNvROluUatFYiqlkFmjAYYEOC+cE6rMFNVmy5DNVAQl7zIdx0w2KY5dGqMKR1unE4c/QzWWoo6cel/HjQUG/79v6eZ4y2L85njll

This only happens with the default parser (espree). But since the code contains TypeScript syntax, a TypeScript-supporting parser has to be specified manually. See https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser for instructions how to do this.

@shawnlauzon
Copy link

This solved it for me, based on the link @FloEdelmann provided:

  parser: 'vue-eslint-parser',
  parserOptions: {
    parser: '@typescript-eslint/parser',
    requireConfigFile: false,
  },

I needed to add the parser option and then install that package and it showed me the real error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: typescript needs repro Need a repository that can reproduce the problem, or a link to DEMO.
Projects
None yet
Development

No branches or pull requests

5 participants