react-starter-kit: ESLint: Unable to resolve path to module
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:
-
project_dir - Mark Directory as > Resource Root
-
yarn add eslint-import-resolver-webpack -D
-
config/default.js
...
resolve: {
// We can now require('file') instead of require('file.jsx')
extensions: ['', '.js', '.jsx', '.scss'],
alias: {
src: path.resolve(__dirname, '../src')
}
},
...
- .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.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 12
- Comments: 24
“import/no-unresolved”: “off”
(as temporary solution)
As @karanssj4 linked to, this seems to be fixed by adding the following to
.eslintrcIf you crawled through here from google and have absolute paths when importing resulting in eslint screaming at you NOT FOUND:
Use eslint-plugin-import:
Here is the answer for eslint Here is the answer for mocha
I think you can add a code recipe for this.
You can use this package
https://www.npmjs.com/package/eslint-import-resolver-webpacktry this https://gist.github.com/karanssj4/7188528ab36fb4e78c8fc385510f3136
What if I already have a
baseUrland custom aliases for paths in myjsconfig.jsonlike this?After I setup eslint, the import aliases doesn’t work anymore, how can I tell eslint to respect the
jsconfig.jsoncompiler options?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.
For me it was a case sensitivity issue. I opened the project using
atom .which gave me path/desktop/apps/my_appwhen i go into atom and open the project manually it’s actually at/Desktop/apps/my_appthis gets rid of the error for me.Maybe you should track this project.https://github.com/benmosher/eslint-plugin-import/issues/496
Working Fine for module aliases.
https://github.com/johvin/eslint-import-resolver-alias
For people using eslint + webpack + single repo
and you may want some overrides if using storybook
You have the option of this lib here
https://github.com/unconfident/eslint-import-resolver-babel-plugin-root-import