eslint-plugin-import: import/extensions breaks when a scoped package's scope is just `@`

In a Vue application, using version with packages:

    "eslint": "^5.2.0",
    "eslint-config-airbnb-base": "^13.2.0",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-vue": "^5.2.3",

and an eslint.js of:

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: ['plugin:vue/essential', 'airbnb-base'],
  rules: {
    'linebreak-style': 0,
    'no-console': 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
    'padded-blocks': 0,
    'no-param-reassign': 0,
    'import/no-unresolved': 0,
    'import/prefer-default-export': 0,
    'max-len': 0,
    'object-curly-newline': ['error', { ObjectPattern: 'never' }],
    // 'vue/html-closing-bracket-newline': ['error', {
    //   singleline: 'never',
    //   multiline: 'never',
    // }],
  },
  parserOptions: {
    parser: 'babel-eslint',
  },
};

In a .vue file, when trying to do an import of a .js file, the eslint plugin can’t decide if the .js extension is needed or not: This: import router from '@/router'; shows: Missing file extension for "@/router" If I change it to: import router from '@/router.js'; I now get: Unexpected use of file extension "js" for "@/router.js"

So which do you want?!?

FYI, the jsconfig.json is:

{
  "include": [
    "./src/**/*"
  ],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "src/*"
      ]
    }
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

@ljharb confirmed, it fixes the issue

So far, this version looks like it’s fixed the issue. I’ll do some more testing but 👍

@ljharb 😢 I forgot to finish the sentences 😭 English is hard

Thanks a lot! Appreciated it.

@ljharb is there any possibility to release the changes to NPM sooner? 🙏

Oh sorry, thought I had mentioned it. When I did change it to be in the format of ‘@src/feedback’, it seem to do the right thing (opposed to keep suggesting the opposite (“add a .js”, or “missing .js”)