johvin / eslint-import-resolver-alias

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias
MIT License
180 stars 10 forks source link

Can not resolve `index.js` under aliased folders? #6

Closed jameschenjav closed 6 years ago

jameschenjav commented 6 years ago

Eslint complains about index.js under aliased folders import/no-unresolved.

For exp, I have folder utils under the path @, it contains a lot of files and index.js to export everything.

import { foo, bar } from '@/utils'; // eslint: `import/no-unresolved`
import { foo, bar } from '@/utils/index'; // adding `index` would work

Anything else like

import store from './store';

which is a folder and contains index.js works fine.

Also my webpack works fine with same settings:

// webpack settings
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      '@': path.resolve(__dirname, './packs'),
    },
  },

My .eslintrc.js


const path = require('path');

module.exports = { root: true, parserOptions: { parser: 'babel-eslint' }, env: { browser: true, }, extends: ['plugin:vue/essential', 'airbnb-base', 'plugin:lodash/recommended'], plugins: [ 'vue', 'lodash', 'lodash-fp', ], settings: { 'import/resolver': { alias: { extensions: ['.js', '.vue', '.json'], map: [ ['@', path.resolve(__dirname, './packs')], ], }, }, }, rules: { 'import/extensions': ['error', 'always', { js: 'never', vue: 'never' }], 'no-param-reassign': ['error', { props: true, ignorePropertyModificationsFor: [ 'state', // for vuex state 'acc', // for reduce accumulators 'e' // for e.returnvalue ] }], 'import/no-extraneous-dependencies': ['error', { optionalDependencies: ['test/unit/index.js'] }], 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', } }


> Dependencies in `package.json` about eslint
```json
    "babel-eslint": "^8.2.3",
    "eslint": "^4.19.1",
    "eslint-config-airbnb-base": "^12.1.0",
    "eslint-friendly-formatter": "^4.0.1",
    "eslint-import-resolver-alias": "^1.1.0",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-lodash": "^2.7.0",
    "eslint-plugin-lodash-fp": "^2.1.3",
    "eslint-plugin-vue": "^4.5.0",

yarn list --depth 0 | grep eslint

├─ babel-eslint@8.2.3
├─ create-eslint-index@1.0.0
├─ eslint-ast-utils@1.1.0
├─ eslint-config-airbnb-base@12.1.0
├─ eslint-friendly-formatter@4.0.1
├─ eslint-import-resolver-alias@1.1.0
├─ eslint-import-resolver-node@0.3.2
├─ eslint-loader@2.0.0
├─ eslint-module-utils@2.2.0
├─ eslint-plugin-import@2.12.0
├─ eslint-plugin-lodash-fp@2.1.3
├─ eslint-plugin-lodash@2.7.0
├─ eslint-plugin-vue@4.5.0
├─ eslint-restricted-globals@0.1.1
├─ eslint-scope@3.7.1
├─ eslint-visitor-keys@1.0.0
├─ eslint@4.19.1
├─ vue-eslint-parser@2.0.3
johvin commented 6 years ago

Got it, thanks for your detailed report and I will reproduce and fix the bug as soon as possible.

jameschenjav commented 6 years ago

johvin commented 6 years ago

@jameschenjav I create a project to reproduce the bug according to your description but everything works fine. My development environment is node: v6.10.2, npm: 3.10.10. Here is the project resolver-alias-debug. You can clone it and try again. If you reproduce the bug, let me know.

jameschenjav commented 6 years ago

不好意思,的确是无法重现这个错误了……想不起来最近有动过什么,最近换了 nvm,unlink 了原来的 npm/npx,但是也记不清是不是这俩礼拜的事儿了,而且理论上也不应该会有影响。

johvin commented 6 years ago

没关系,有问题欢迎再提出来 😊

Lpaydat commented 4 years ago

I face a similar issue, but in my case, the error occurs only if the path has only one level depth.

For example,

import { foo, bar } from '@test' // cannot find module '@test'. ts(2307)
import { foo, bar } from '@test/index' // work!!

p.s. I use typescript, not sure if this related

espipj commented 4 years ago

@Lpaydat this happens to me as well, did you manage to fix it?

AntonioErdeljac commented 3 years ago

Any news on this?