eslint-plugin-import: Unable to resolve path to module (import/no-resolved) only in Sublime text 3

I have an Error “Unable to resolve path to module” (import/no-resolved) only in Sublime text 3 for any of my es6 module import statements. At the same time, I have no problems with bundling, and properly working highlighted export of multiple variables, e.g. :

export { export1, export2, export3 };

and other eslint-plugin-import rules I have node 5.0.0 installed via nvm, all dependency modules removed, and npm i this is totally wierd( I kill 2 days for it.

can’t use “eslint-import-resolver-webpack”: “^0.1.4”, because I use gulp-webpack plugin with configuration in gulpfile.js instead of separate webpack.config.js , and have several pages in build process.

I’m trying to slowly integrate ReactJS in my project, which I have frameworkless pure functional ES5, and now I’m converting it to ES6, before I can start with React and single webpack.config.js

Please, can somebody help me out? I kill 2 days desperately fight this problem.

.eslintrc

{
  "parser": "babel-eslint",
  "env": {
    "node": true,
    "browser": true,
    "commonjs": true,
    "worker": true,
    "mocha": true,
    "mongo": true,
    "es6": true
  },
  "ecmaFeatures": {
    "arrowFunctions": true,
    "blockBindings": true,
    "destructuring": true,
    "modules": true,
    "spread": true,
    "templateStrings": true,
    "forOf": true
  },
  "plugins": [
    "react",
    "import"
  ],
  "settings": {
    "ecmascript": 6,
    "jsx": true
  },
  "rules": {
    "quotes": 2,
    "no-unused-vars": 2,
    "camelcase": 0,
    "no-underscore-dangle": 0,

    "indent": [2, 2, {"VariableDeclarator": { "var": 2, "let": 2, "const": 3}}],
    "comma-dangle": [2, "never"],
    "no-dupe-args": 2,
    "no-dupe-keys": 2,
    "no-empty": 2,
    "no-extra-boolean-cast": 2,
    "no-extra-parens": 2,
    "no-extra-semi": 2,
    "no-func-assign": 2,
    "no-inner-declarations": 2,
    "no-irregular-whitespace": 2,
    "no-negated-in-lhs": 2,
    "no-sparse-arrays": 2,
    "no-unexpected-multiline": 2,
    "no-unreachable": 2,
    "use-isnan": 2,
    "valid-jsdoc": 2,
    "valid-typeof": 2,

    "block-scoped-var": 2,
    "curly": [2, "multi-line"],
    "default-case": 2,
    "guard-for-in": 2,
    "no-alert": 2,
    "no-caller": 2,
    "no-case-declarations": 2,
    "no-else-return": 2,
    "no-empty-label": 2,
    "no-empty-pattern": 2,
    "no-eq-null": 2,
    "no-eval": 2,

    "import/default": 2,
    "import/no-unresolved": 2,
    "import/named": 2,
    "import/namespace": 2,
    "import/export": 2,
    "import/no-duplicates": 2,
    "import/imports-first": 2
  },
  "syntax_map": {
    "JavaScript (Babel)": "javascript",
  }
}

package.json

"devDependencies": {
    "babel-core": "^6.2.1",
    "babel-eslint": "^4.1.6",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "eslint": "^1.10.2",
    "eslint-import-resolver-webpack": "^0.1.4",
    "eslint-loader": "^1.1.1",
    "eslint-plugin-import": "^0.11.0",
    "eslint-plugin-react": "^3.11.1",
    "eslint_d": "^2.3.2",
    "gulp": "3.9.0",
    "gulp-babel": "^6.1.0",
    "gulp-webpack": "^1.5.0",
    "webpack": "^1.12.9"
  }

.sublimelinterrc

{
  "linters": {
    "eslint": {
      "args": ["--stdin-filename", "@"]
    }
  }
}

SublimeLinter.sublime-settings

{
    "user": {
        "debug": false,
        "delay": 0.25,
        "error_color": "D02000",
        "gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
        "gutter_theme_excludes": [],
        "lint_mode": "background",
        "linters": {
            "eslint": {
                "@disable": false,
                "args": [],
                "excludes": []
            },
            "eslint_d": {
                "@disable": false,
                "args": [],
                "excludes": []
            }
        },
        "mark_style": "outline",
        "no_column_highlights_line": false,
        "passive_warnings": false,
        "paths": {
            "linux": [],
            "osx": [
                "/Users/justfly/.nvm/versions/node/v5.0.0/bin/node"
            ],
            "windows": []
        },
        "python_paths": {
            "linux": [],
            "osx": [],
            "windows": []
        },
        "rc_search_limit": null,
        "shell_timeout": 10,
        "show_errors_on_save": false,
        "show_marks_in_minimap": true,
        "syntax_map": {
            "html (django)": "html",
            "html (rails)": "html",
            "html 5": "html",
            "javascript (babel)": "javascript",
            "magicpython": "python",
            "php": "html",
            "python django": "python"
        },
        "warning_color": "DDB700",
        "wrap_find": true
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 41 (15 by maintainers)

Most upvoted comments

@adrianmcli I just figured out the issue I had. My projectRoot/.eslintrc file

"settings": {
  "import/resolver": {
    "webpack": {
      "config": "./webpack/webpack.eslint.js"
    }
  }
}

Originally in my projectRoot/webpack/webpack.eslint.js file, I had

const path = require('path');

module.exports = {
  context: process.cwd(),
  resolve: {
    modules: [
      path.resolve('./src/')
    ]
  }
};

Even though this works with Atom, it does not with Sublime.

I realized that Sublime was changing the context (process.cwd()) to the directory of the open file. Thus eslint was unable to find the local modules. So I changed my projectRoot/webpack/webpack.eslint.js file:

const path = require('path');

module.exports = {
  resolve: {
    modules: [
      path.resolve(__dirname, '..', 'src')
    ]
  }
};

So I was able to fix the problem by providing the full path to my src directory.

Thanks, @emorikawa! Had the same error for imports of .jsx files without specifying the extension.

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

Before that tried different settings, including "settings": {"import/extensions": [".js", ".jsx"] } which didn’t help.

Using version 1.6.1.

I had a different problem with the same error. We use extension-less imports but point to more types of files (.es6, .coffee, etc).

I added the following line to my eslint.json and got it to work:

  "settings": {
    "import/resolver": {"node": {"extensions": [".es6", ".coffee"]}}
  }

The workaround that worked for me was:

Preferences > Packages settings > SublimeLinter > Settings [User]

Then add "args": ["--stdin-filename", "@"] to the linters.eslint entry

I have tried everything in the README, as well as every single proposed solution in this issue.

Setup

My installed versions:

{
"eslint-import-resolver-webpack": "^0.8.0",
"eslint-plugin-import": "^2.2.0"
}

My problem

I am getting the following linting errors ONLY on Sublime 3. If I run eslint from the console, I do not get these errors at all:

SublimeLinter: eslint: app.js ['/Users/liadrian/Dev/robinapp-web/node_modules/.bin/eslint', '--format', 'compact', '--stdin', '--stdin-filename', '@', '--stdin-filename', '@'] 
SublimeLinter: eslint output:
/Users/liadrian/Dev/robinapp-web/src/@: line 7, col 1, Error - 'setup' should be listed in the project's dependencies. Run 'npm i -S setup' to add it (import/no-extraneous-dependencies)
/Users/liadrian/Dev/robinapp-web/src/@: line 7, col 23, Error - Unable to resolve path to module 'setup/store'. (import/no-unresolved)
/Users/liadrian/Dev/robinapp-web/src/@: line 7, col 23, Error - Missing file extension for "setup/store" (import/extensions)

4 problems

The code

From {project_root}/src/app.js, I am trying to import {project_root}/src/setup/store.js, like this:

import initStore from 'setup/store';

Note again that this works in every instance, just not on Sublime 3 for some reason.

Config files

My Webpack config uses ./src for root resolution, so the app compiles fine:

// ...
resolve: {
  root: path.resolve('./src'),
  extensions: ['', '.js'],
},
// ...

I put in a .sublime-project file:

{
    "folders":
    [
        {
            "path": "src"
        }
    ],
    "SublimeLinter":
    {
        "linters":
        {
            "eslint":
            {
                "chdir": "${project}/src"
            }
        }
    }
}

In my SublimeLinter.sublime-settings (aka Preferences > Package Settings > SublimeLinter > Settings - User):

"linters": {
    "eslint": {
        "@disable": false,
        "args": [
            "--stdin-filename",
            "@"
        ],
        "excludes": []
    }
},
"rc_search_limit": null,

And finally, my .eslintrc file:

{
  "ecmaFeatures": {
    "jsx": true,
    "modules": true
  },
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "parser": "babel-eslint",
  "extends": "eslint-config-airbnb",
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
  },
  "plugins": [
    "react"
  ],
  "settings": {
    "import/extensions": [".js", ".jsx"],
    "import/parser": "babel-eslint",
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx"]
      },
      "webpack": {
        "config": "webpack.dev.config.js"
      }
    }
  }
}

What am I missing?

using

import/resolver:
  node:
    extensions:
    - '.js'
    - '.jsx'

worked for me. Should add this to the README