eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.9k stars 4.5k forks source link

Vue lazy loading components import is marked as "no-undef" #13984

Closed lmaldonadoch closed 3 years ago

lmaldonadoch commented 3 years ago

Tell us about your environment

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

Please show your full configuration:

Configuration ```js module.exports = { env: { browser: true, es2020: true, amd: true, }, extends: ["eslint:recommended", "plugin:vue/essential"], parserOptions: { ecmaVersion: 11, sourceType: "module", }, plugins: ["vue"], rules: {}, overrides: [ { files: [ "**/__tests__/*.{j,t}s?(x)", "**/tests/unit/**/*.spec.{j,t}s?(x)", ], env: { jest: true, }, }, { files: ["**/*.config.js", "**/tests/e2e/**/*.js"], rules: { "no-undef": "off", }, }, ], }; ```

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

export default {
  components: {
    VueApexCharts,
    StatisticsCardLine,
    VuePerfectScrollbar: () => imoprt(/* webpackPrefetch: true */ 'vue-perfect-scrollbar'),
    ChangeTimeDurationDropdown: () => import(/* webpackPrefetch: true */ '@/components/ChangeTimeDurationDropdown.vue'),
  },
...
}
$ yarn run vue-cli-service lint -- --fix

What did you expect to happen? Show no error on the when lazy-loading component.

What actually happened? Please include the actual, raw output from ESLint. Eslint is finding an error in the import of the file when I attempt to lazy-load the component.

error: 'imoprt' is not defined (no-undef) at src/views/dashboard/Summary.vue:331:32:
  329 |     VueApexCharts,
  330 |     StatisticsCardLine,
> 331 |     VuePerfectScrollbar: () => imoprt(/* webpackPrefetch: true */ 'vue-perfect-scrollbar'),

Are you willing to submit a pull request to fix this bug? Yes!

lmaldonadoch commented 3 years ago

Seems like this happens with lazy-loaded unused components. I think a different error message would be great. I'm sorry I didn't catch this before opening the issue as a bug.

mdjermanovic commented 3 years ago

Hi @lmaldonadoch, thanks for the issue!

It looks like there's a typo imoprt instead of import, so the rule correctly reports that a variable named "imoprt" isn't defined.

btmills commented 3 years ago

Closing as this looks to be an accurate error. @lmaldonadoch if it still reports after fixing the typo, let us know.