react-starter-kit icon indicating copy to clipboard operation
react-starter-kit copied to clipboard

ESLint: Unable to resolve path to module

Open comerc opened this issue 9 years ago • 24 comments

We have solution for absolute path, like this:

import MyComponent from 'src/components/MyComponent'

It is work fine for yarn start, but for yarn lint:

Unable to resolve path to module 'src/components/MyComponent'     import/no-unresolved

I have solution for my other project (no RSK) with WebStorm:

  1. project_dir - Mark Directory as > Resource Root

  2. yarn add eslint-import-resolver-webpack -D

  3. config/default.js

...
	resolve: {
		// We can now require('file') instead of require('file.jsx')
		extensions: ['', '.js', '.jsx', '.scss'],
		alias: {
			src: path.resolve(__dirname, '../src')
		}
	},
...

  1. .eslintrc.js

/* global __dirname */

const path = require('path');

...
	settings: {
		'import/resolver': {
			webpack: {
				config: path.join(__dirname, '/config', 'default.js')
			}
		}
	}
...

How to solve this issue for RSK? Please help me.

comerc avatar Mar 18 '17 09:03 comerc

"import/no-unresolved": "off"

(as temporary solution)

comerc avatar Mar 18 '17 11:03 comerc

Maybe you should track this project.https://github.com/benmosher/eslint-plugin-import/issues/496

Stupidism avatar Mar 23 '17 22:03 Stupidism

Aha~ I'm facing a same issue like you I wanted to do absolute imports with a special prefix(So I can tell what's extenal easily). #1193 I fixed the mocha test to work with this using-webpack-aliases-in-mocha-tests/ Now I don't know how to eslint it. I used to solve this problem by eslint-import-resolver-webpack in another project. However, it seems not working with newest webpack.

Stupidism avatar Mar 24 '17 02:03 Stupidism

Update: you will face the test problem, too.

Stupidism avatar Mar 24 '17 02:03 Stupidism

Here is the answer for eslint Here is the answer for mocha

I think you can add a code recipe for this.

Stupidism avatar Mar 24 '17 02:03 Stupidism

try this https://gist.github.com/karanssj4/7188528ab36fb4e78c8fc385510f3136

karanssj4 avatar Mar 02 '18 08:03 karanssj4

For me it was a case sensitivity issue. I opened the project using atom . which gave me path /desktop/apps/my_app when i go into atom and open the project manually it's actually at /Desktop/apps/my_app this gets rid of the error for me.

MattEhrlich avatar Apr 13 '18 22:04 MattEhrlich

You have the option of this lib here

https://github.com/unconfident/eslint-import-resolver-babel-plugin-root-import

lucasdu4rte avatar Sep 18 '18 11:09 lucasdu4rte

As @karanssj4 linked to, this seems to be fixed by adding the following to .eslintrc

  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    }
  },

skube avatar Nov 07 '18 19:11 skube

If you crawled through here from google and have absolute paths when importing resulting in eslint screaming at you NOT FOUND:

Use eslint-plugin-import:

// App.js
import { ComponentName } from 'components/ComponentName';
// .eslintrc.js
module.exports = {
  ...   
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"],
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    },
  },
}

0x73706f6f6b avatar Dec 13 '18 20:12 0x73706f6f6b

// .eslintrc.json

"settings": {
        "import/resolver": {
            "node": {
                "paths": ["src"],
                "extensions": [".js", ".jsx", ".ts", ".tsx"]
            }
        }
    }

moelzanaty3 avatar Jan 19 '19 16:01 moelzanaty3

You can use this package https://www.npmjs.com/package/eslint-import-resolver-webpack

"settings": {
    "import/resolver": "webpack"
  }

piavgh avatar Aug 30 '19 07:08 piavgh

Solved here for TS : https://stackoverflow.com/questions/55198502/using-eslint-with-typescript-unable-to-resolve-path-to-module

vianneyguesdon avatar Sep 03 '19 13:09 vianneyguesdon

"settings": {
        "import/resolver": {
          "node": {
            "paths": ["src"],
            "extensions": [".js", ".ts", ".d.ts"]
          }
        }
      }

saravanakumargn avatar Sep 23 '19 02:09 saravanakumargn

If you crawled through here from google and have absolute paths when importing resulting in eslint screaming at you NOT FOUND:

Use eslint-plugin-import:

// App.js
import { ComponentName } from 'components/ComponentName';
// .eslintrc.js
module.exports = {
  ...   
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"],
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    },
  },
}

great solution thanks

dbeetoven avatar Apr 02 '20 18:04 dbeetoven

I just needed

"settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx"]
      }
    },
  }

🎉

milieu avatar May 14 '20 04:05 milieu

For people using eslint + webpack + single repo

// .eslintrc.js
module.exports = {
  ...   
  "settings": {
    "import/resolver": {
       node: {
         paths: [".", "app", "lib", "functions"], //name the subproject folders here!!!
         extensions: [".js", ".jsx", ".ts", ".tsx"]
      }
    },
  },
}

and you may want some overrides if using storybook

// .eslintrc.js
module.exports = {
  ...   
  overrides: [
    {
      files: ["**/*.stories.tsx", "backend/**/*", "storybook/**/*"],
      rules: {
        "import/no-unresolved": "off",
      },
    },
  ],
}

ploth avatar Sep 07 '20 15:09 ploth

Unable to resolve path to module 'buefy'

Noxiess avatar Oct 01 '20 15:10 Noxiess

Working Fine for module aliases.

https://github.com/johvin/eslint-import-resolver-alias

vijaybajrot avatar Oct 29 '20 07:10 vijaybajrot

"import/no-unresolved": "off"

Where to put this? Which file?

Sedose avatar Feb 21 '21 05:02 Sedose