question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

    "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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Lpaydatcommented, Oct 28, 2019

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

1reaction
AntonioErdeljaccommented, May 28, 2021

Any news on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why create-react-app alias is not able to find index.js from ...
Common practice is to create symlinks in src folder for modules outside it and set up aliases to resolve from the src folder....
Read more >
How to solve the problem with unresolved path aliases in ...
Check the index.js in the output (build) folder β€” Now, the path is resolved from alias (@modules/myfunction) back to absolute (.
Read more >
Typescript – How to solve the problem with unresolved path ...
Check the index.js in the output (build) folder – Now, the path is resolved from alias (@modules/myfunction) back to absolute (./app/Β ...
Read more >
Resolve | webpack
index.js may resolve to another file if defined in the package.json . ... Setting resolve.alias to false will tell webpack to ignore a...
Read more >
Module Resolution or Import Alias: The Final Guide - Raul Melo
How can I add aliases to my imports? The idea here is to do not stitch in any specific framework/tool but to give...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found