Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error getting eslint to work with eslint-plugin-vue

I'm not a front-end dev but am trying to lint my javascript / Vue.js file in a Rails 5.1 app. I'm not that familiar with the node ecosystem. I get the following error and wanted to know where to start to fix this:

Tue Apr 17$ eslint javascript/ --ext .vue
Cannot find module 'eslint-plugin-vue'
Referenced from: /Users/jt/repos/embers2/.eslintrc.js
Error: Cannot find module 'eslint-plugin-vue'
Referenced from: /Users/jt/repos/embers2/.eslintrc.js
    at ModuleResolver.resolve (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/util/module-resolver.js:74:19)
    at resolve (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:466:29)
    at load (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:542:26)
    at configExtends.reduceRight (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:421:36)
    at Array.reduceRight (<anonymous>)
    at applyExtends (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:403:28)
    at loadFromDisk (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:514:22)
    at Object.load (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config/config-file.js:550:20)
    at Config.getLocalConfigHierarchy (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config.js:228:44)
    at Config.getConfigHierarchy (/usr/local/lib/node_modules/eslint-config-airbnb-standard/node_modules/eslint/lib/config.js:180:43)
Tue Apr 17$ 

My .eslint.js file is:

module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // 'eslint:recommended',
    'plugin:vue/essential',
    'airbnb-base'

  ],
  rules: {
    // override/add rules settings here, such as:
    // 'vue/no-unused-vars': 'error'
  }
};

and my package.json is:

{
  "dependencies": {
    "@rails/webpacker": "^3.4.3",
    "axios": "^0.17.1",
    "coffeescript": "1.12.7",
    "octicons": "^6.0.1",
    "postcss-smart-import": "^0.7.6",
    "solc": "^0.4.19",
    "vue": "^2.5.16",
    "vue-awesome": "^2.3.4",
    "vue-cookie": "^1.1.4",
    "vue-loader": "^14.2.2",
    "vue-moment": "^3.2.0",
    "vue-octicon": "^2.1.1",
    "vue-progressbar": "^0.7.3",
    "vue-router": "^2.7.0",
    "vue-template-compiler": "^2.5.16",
    "vue2-google-maps": "^0.8.10",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-vue": "^4.4.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "vue-masonry-css": "^1.0.1",
    "webpack-cli": "^2.0.13",
    "webpack-dev-server": "2.11.1"
  }
}

Where do I start looking to debug this? This ecosystem is still very opaque to me.


On a comment's request, I ran npm install and verified that the plugin appears to be in ./node_modules/:

"eslint-plugin-vue" is in the node_modules folder

But I'm still getting the same error. Any other ideas?

like image 875
timpone Avatar asked Apr 17 '18 23:04

timpone


1 Answers

You need to set the eslint working directories in .vscode/settings.json as following

{
  "eslint.workingDirectories": [
    "./client",
  ]
}

Here, ./client path is relative to where you initiated your visual studio code i.e. where your project root is

enter image description here

like image 164
Ayan Avatar answered Sep 24 '22 13:09

Ayan