import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.58k stars 1.57k forks source link

`eslint` loads webpack's config but not really works #692

Open dickeylth opened 7 years ago

dickeylth commented 7 years ago

I have the .eslintrc under my project:

{

  // I want to use babel-eslint for parsing!
  "parser": "babel-eslint",

  "env": {
    "browser": true,
    "es6": true,
    "commonjs": true
  },
  "ecmaFeatures": {
    "jsx": true,
    "modules": true
  },

  "plugins": ["react", "import"],

  "extends": "airbnb",

  "globals": {
  },

  "rules": {
    "comma-dangle": [2, "only-multiline"],
    "react/jsx-closing-bracket-location": [1, "after-props"],
    "no-new": 1,
    "new-cap": ["warn", {"capIsNewExceptions": ["CSSModules"]}]
  },

  "settings": {
    "import/resolver": {
      "webpack": {
        "config": "./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js"
      }
    }
  }
}

and dependencies:

"devDependencies": {
    "eslint": "^3.12.2",
    "eslint-config-airbnb": "^13.0.0",
    "eslint-import-resolver-webpack": "^0.8.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^2.2.3",
    "eslint-plugin-react": "^6.8.0",
    "grunt-eslint": "^19.0.0"
}

and I tried DEBUG=eslint-plugin-import:* grunt eslint:

h5-react-project ➤ DEBUG=eslint-plugin-import:* grunt eslint                                                                        
[Webpack Entry Map]: {
  "pages/detail/index": "./pages/detail/index.jsx",
  "pages/home/index": "./pages/home/index.jsx"
}
Running "eslint:main" (eslint) task
  eslint-plugin-import:resolver:node Resolving: ./test.scss from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/index.jsx +0ms
  eslint-plugin-import:resolver:node Resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/test.scss +2ms
  eslint-plugin-import:resolver:node Resolving: base from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/index.jsx +10ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'base' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail'
    at Function.module.exports [as sync] (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/node_modules/resolve/lib/sync.js:36:11)
    at Object.exports.resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/index.js:19:28)
    at v2 (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:79:23)
    at withResolver (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:84:16)
    at fullResolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:101:22)
    at relative (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:46:10)
    at resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:172:12)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at EventEmitter.checkSource (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +11ms
  eslint-plugin-import:resolver:webpack Config path from settings: ./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +0ms
  eslint-plugin-import:resolver:webpack Config path resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +2ms
  eslint-plugin-import:resolver:webpack Using config:  { entry: 
   { 'pages/detail/index': './pages/detail/index.jsx',
     'pages/home/index': './pages/home/index.jsx' },
  context: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src',
  output: 
   { path: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/build',
     filename: '[name].entry.js',
     libraryTarget: 'umd',
     library: [ 'h5-react-project', '[name]' ],
     umdNamedDefine: true },
  stats: { colors: true },
  storeStatsTo: 'webpack-stats',
  progress: true,
  failsOnError: false,
  watch: true,
  keepalive: false,
  inline: true,
  plugins: 
   [ ExtractTextPlugin { filename: '[name].css', options: {}, id: 1 },
     DefinePlugin { definitions: [Object] },
     DedupePlugin {},
     ResolverPlugin { plugins: [Object], types: [Object] },
     OccurrenceOrderPlugin { preferEntry: undefined },
     NoErrorsPlugin {},
     CommonsChunkPlugin {
       chunkNames: 'h5-react-project-commons',
       filenameTemplate: undefined,
       minChunks: null,
       selectedChunks: undefined,
       async: undefined,
       minSize: undefined,
       excludeModuleFn: [Function],
       ident: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/clam-webpack-plugin/CommonsChunk.js0' } ],
  devServer: 
   { inline: true,
     hot: true,
     headers: { 'Cache-Control': 'no-cache' } },
  postcss: [Function: postcss],
  resolve: 
   { extensions: [ '', '.js', '.jsx', '.vue' ],
     root: 
      [ '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/widgets',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@alife' ],
     alias: 
      { '@mods': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods',
        '@pages': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages' } },
  externals: [ 'base' ],
  module: 
   { loaders: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } } +1ms
  eslint-plugin-import:resolver:node Resolving: @mods/header/index from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/index.jsx +91ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module '@mods/header/index' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail'
    at Function.module.exports [as sync] (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/node_modules/resolve/lib/sync.js:36:11)
    at Object.exports.resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/index.js:19:28)
    at v2 (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:79:23)
    at withResolver (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:84:16)
    at fullResolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:101:22)
    at relative (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:46:10)
    at resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:172:12)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at EventEmitter.checkSource (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +3ms
  eslint-plugin-import:resolver:webpack Config path from settings: ./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +25ms
  eslint-plugin-import:resolver:webpack Config path resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +0ms
  eslint-plugin-import:resolver:webpack Using config:  { entry: 
   { 'pages/detail/index': './pages/detail/index.jsx',
     'pages/home/index': './pages/home/index.jsx' },
  context: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src',
  output: 
   { path: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/build',
     filename: '[name].entry.js',
     libraryTarget: 'umd',
     library: [ 'h5-react-project', '[name]' ],
     umdNamedDefine: true },
  stats: { colors: true },
  storeStatsTo: 'webpack-stats',
  progress: true,
  failsOnError: false,
  watch: true,
  keepalive: false,
  inline: true,
  plugins: 
   [ ExtractTextPlugin { filename: '[name].css', options: {}, id: 1 },
     DefinePlugin { definitions: [Object] },
     DedupePlugin {},
     ResolverPlugin { plugins: [Object], types: [Object] },
     OccurrenceOrderPlugin { preferEntry: undefined },
     NoErrorsPlugin {},
     CommonsChunkPlugin {
       chunkNames: 'h5-react-project-commons',
       filenameTemplate: undefined,
       minChunks: null,
       selectedChunks: undefined,
       async: undefined,
       minSize: undefined,
       excludeModuleFn: [Function],
       ident: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/clam-webpack-plugin/CommonsChunk.js0' } ],
  devServer: 
   { inline: true,
     hot: true,
     headers: { 'Cache-Control': 'no-cache' } },
  postcss: [Function: postcss],
  resolve: 
   { extensions: [ '', '.js', '.jsx', '.vue' ],
     root: 
      [ '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/widgets',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@alife' ],
     alias: 
      { '@mods': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods',
        '@pages': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages' } },
  externals: [ 'base' ],
  module: 
   { loaders: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } } +0ms
  eslint-plugin-import:resolver:webpack enhanced-resolve version: 0.9.1 +6ms
  eslint-plugin-import:rules:newline-after-import exit processing for /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/index.jsx +110ms
  eslint-plugin-import:rules:newline-after-import got scope: [ ......
  eslint-plugin-import:resolver:node Resolving: ./index.scss from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.jsx +113ms
  eslint-plugin-import:resolver:node Resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.scss +1ms
  eslint-plugin-import:resolver:node Resolving: base from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.jsx +3ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'base' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home'
    at Function.module.exports [as sync] (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/node_modules/resolve/lib/sync.js:36:11)
    at Object.exports.resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/index.js:19:28)
    at v2 (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:79:23)
    at withResolver (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:84:16)
    at fullResolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:101:22)
    at relative (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:46:10)
    at resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:172:12)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at EventEmitter.checkSource (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +2ms
  eslint-plugin-import:resolver:webpack Config path from settings: ./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +225ms
  eslint-plugin-import:resolver:webpack Config path resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +1ms
  eslint-plugin-import:resolver:webpack Using config:  { entry: 
   { 'pages/detail/index': './pages/detail/index.jsx',
     'pages/home/index': './pages/home/index.jsx' },
  context: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src',
  output: 
   { path: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/build',
     filename: '[name].entry.js',
     libraryTarget: 'umd',
     library: [ 'h5-react-project', '[name]' ],
     umdNamedDefine: true },
  stats: { colors: true },
  storeStatsTo: 'webpack-stats',
  progress: true,
  failsOnError: false,
  watch: true,
  keepalive: false,
  inline: true,
  plugins: 
   [ ExtractTextPlugin { filename: '[name].css', options: {}, id: 1 },
     DefinePlugin { definitions: [Object] },
     DedupePlugin {},
     ResolverPlugin { plugins: [Object], types: [Object] },
     OccurrenceOrderPlugin { preferEntry: undefined },
     NoErrorsPlugin {},
     CommonsChunkPlugin {
       chunkNames: 'h5-react-project-commons',
       filenameTemplate: undefined,
       minChunks: null,
       selectedChunks: undefined,
       async: undefined,
       minSize: undefined,
       excludeModuleFn: [Function],
       ident: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/clam-webpack-plugin/CommonsChunk.js0' } ],
  devServer: 
   { inline: true,
     hot: true,
     headers: { 'Cache-Control': 'no-cache' } },
  postcss: [Function: postcss],
  resolve: 
   { extensions: [ '', '.js', '.jsx', '.vue' ],
     root: 
      [ '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/widgets',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@alife' ],
     alias: 
      { '@mods': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods',
        '@pages': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages' } },
  externals: [ 'base' ],
  module: 
   { loaders: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } } +1ms
  eslint-plugin-import:resolver:node Resolving: @mods/header/index from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.jsx +36ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module '@mods/header/index' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home'
    at Function.module.exports [as sync] (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/node_modules/resolve/lib/sync.js:36:11)
    at Object.exports.resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/index.js:19:28)
    at v2 (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:79:23)
    at withResolver (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:84:16)
    at fullResolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:101:22)
    at relative (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:46:10)
    at resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:172:12)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at EventEmitter.checkSource (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +2ms
  eslint-plugin-import:resolver:webpack Config path from settings: ./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +37ms
  eslint-plugin-import:resolver:webpack Config path resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +1ms
  eslint-plugin-import:resolver:webpack Using config:  { entry: 
   { 'pages/detail/index': './pages/detail/index.jsx',
     'pages/home/index': './pages/home/index.jsx' },
  context: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src',
  output: 
   { path: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/build',
     filename: '[name].entry.js',
     libraryTarget: 'umd',
     library: [ 'h5-react-project', '[name]' ],
     umdNamedDefine: true },
  stats: { colors: true },
  storeStatsTo: 'webpack-stats',
  progress: true,
  failsOnError: false,
  watch: true,
  keepalive: false,
  inline: true,
  plugins: 
   [ ExtractTextPlugin { filename: '[name].css', options: {}, id: 1 },
     DefinePlugin { definitions: [Object] },
     DedupePlugin {},
     ResolverPlugin { plugins: [Object], types: [Object] },
     OccurrenceOrderPlugin { preferEntry: undefined },
     NoErrorsPlugin {},
     CommonsChunkPlugin {
       chunkNames: 'h5-react-project-commons',
       filenameTemplate: undefined,
       minChunks: null,
       selectedChunks: undefined,
       async: undefined,
       minSize: undefined,
       excludeModuleFn: [Function],
       ident: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/clam-webpack-plugin/CommonsChunk.js0' } ],
  devServer: 
   { inline: true,
     hot: true,
     headers: { 'Cache-Control': 'no-cache' } },
  postcss: [Function: postcss],
  resolve: 
   { extensions: [ '', '.js', '.jsx', '.vue' ],
     root: 
      [ '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/widgets',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@alife' ],
     alias: 
      { '@mods': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods',
        '@pages': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages' } },
  externals: [ 'base' ],
  module: 
   { loaders: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } } +0ms
  eslint-plugin-import:resolver:webpack enhanced-resolve version: 0.9.1 +3ms
  eslint-plugin-import:rules:newline-after-import exit processing for /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.jsx +18ms
  eslint-plugin-import:rules:newline-after-import got scope: ......
  eslint-plugin-import:resolver:node Resolving: base from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header/index.jsx +138ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'base' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header'
    at Function.module.exports [as sync] (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/node_modules/resolve/lib/sync.js:36:11)
    at Object.exports.resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-import-resolver-node/index.js:19:28)
    at v2 (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:79:23)
    at withResolver (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:84:16)
    at fullResolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:101:22)
    at relative (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:46:10)
    at resolve (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/resolve.js:172:12)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50)
    at checkSourceValue (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at EventEmitter.checkSource (/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/eslint-plugin-import/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +3ms
  eslint-plugin-import:resolver:webpack Config path from settings: ./node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +153ms
  eslint-plugin-import:resolver:webpack Config path resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali/grunt-default-config/lib/webpack.eslint.config.js +2ms
  eslint-plugin-import:resolver:webpack Using config:  { entry: 
   { 'pages/detail/index': './pages/detail/index.jsx',
     'pages/home/index': './pages/home/index.jsx' },
  context: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src',
  output: 
   { path: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/build',
     filename: '[name].entry.js',
     libraryTarget: 'umd',
     library: [ 'h5-react-project', '[name]' ],
     umdNamedDefine: true },
  stats: { colors: true },
  storeStatsTo: 'webpack-stats',
  progress: true,
  failsOnError: false,
  watch: true,
  keepalive: false,
  inline: true,
  plugins: 
   [ ExtractTextPlugin { filename: '[name].css', options: {}, id: 1 },
     DefinePlugin { definitions: [Object] },
     DedupePlugin {},
     ResolverPlugin { plugins: [Object], types: [Object] },
     OccurrenceOrderPlugin { preferEntry: undefined },
     NoErrorsPlugin {},
     CommonsChunkPlugin {
       chunkNames: 'h5-react-project-commons',
       filenameTemplate: undefined,
       minChunks: null,
       selectedChunks: undefined,
       async: undefined,
       minSize: undefined,
       excludeModuleFn: [Function],
       ident: '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/clam-webpack-plugin/CommonsChunk.js0' } ],
  devServer: 
   { inline: true,
     hot: true,
     headers: { 'Cache-Control': 'no-cache' } },
  postcss: [Function: postcss],
  resolve: 
   { extensions: [ '', '.js', '.jsx', '.vue' ],
     root: 
      [ '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/widgets',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@ali',
        '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/node_modules/@alife' ],
     alias: 
      { '@mods': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods',
        '@pages': '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages' } },
  externals: [ 'base' ],
  module: 
   { loaders: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } } +1ms
  eslint-plugin-import:resolver:node Resolving: ./index.scss from: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header/index.jsx +16ms
  eslint-plugin-import:resolver:node Resolved to: /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header/index.scss +1ms
  eslint-plugin-import:rules:newline-after-import exit processing for /Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header/index.jsx +73ms
  eslint-plugin-import:rules:newline-after-import got scope: ......
/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail/index.jsx
   7:1   error    'base' should be listed in the project's dependencies. Run 'npm i -S base' to add it                  import/no-extraneous-dependencies
   7:59  error    Absolute imports should come before relative imports                                                  import/first
   7:59  error    Missing file extension for "base"                                                                     import/extensions
  10:1   warning  Unexpected console statement                                                                          no-console
  20:1   error    Import in body of module; reorder to top                                                              import/first
  20:1   error    '@mods/header' should be listed in the project's dependencies. Run 'npm i -S @mods/header' to add it  import/no-extraneous-dependencies
  20:24  error    Absolute imports should come before relative imports                                                  import/first

/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home/index.jsx
   8:1   error    'base' should be listed in the project's dependencies. Run 'npm i -S base' to add it                  import/no-extraneous-dependencies
   8:59  error    Absolute imports should come before relative imports                                                  import/first
   8:59  error    Missing file extension for "base"                                                                     import/extensions
  11:1   warning  Unexpected console statement                                                                          no-console
  24:3   warning  Unexpected console statement                                                                          no-console
  27:3   warning  Unexpected console statement                                                                          no-console
  30:3   warning  Unexpected console statement                                                                          no-console
  39:8   error    Expected parentheses around arrow function argument having a body with curly braces                   arrow-parens
  40:3   warning  Unexpected console statement                                                                          no-console
  41:4   error    Expected parentheses around arrow function argument having a body with curly braces                   arrow-parens
  42:3   warning  Unexpected console statement                                                                          no-console
  46:1   error    Import in body of module; reorder to top                                                              import/first
  46:1   error    '@mods/header' should be listed in the project's dependencies. Run 'npm i -S @mods/header' to add it  import/no-extraneous-dependencies
  46:24  error    Absolute imports should come before relative imports                                                  import/first

/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/mods/header/index.jsx
   6:1   error  'base' should be listed in the project's dependencies. Run 'npm i -S base' to add it  import/no-extraneous-dependencies
   6:1   error  Expected empty line after import statement not followed by another import             import/newline-after-import
   6:23  error  Missing file extension for "base"                                                     import/extensions
   9:1   error  Import in body of module; reorder to top                                              import/first
  66:9   error  Using string literals in ref attributes is deprecated                                 react/no-string-refs
  68:23  error  Unexpected usage of singlequote                                                       jsx-quotes
  69:23  error  Unexpected usage of singlequote                                                       jsx-quotes

✖ 28 problems (21 errors, 7 warnings)

Warning: Task "eslint:main" failed. Use --force to continue.

Aborted due to warnings.

Execution Time (2016-12-19 08:05:28 UTC)
loading tasks         188ms  ▇▇▇▇▇▇▇ 7%
loading grunt-eslint  310ms  ▇▇▇▇▇▇▇▇▇▇▇ 11%
eslint:main            2.3s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 82%
Total 2.8s

I've specified externals: [ 'base' ], in webpack config, however eslint still throws Error: Cannot find module 'base' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/home';

and I've specified resolve: {alias: { '@mods': 'dir', '@pages': 'dir' } },} in webpack config, however eslint still throws eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module '@mods/header/index' from '/Users/hongshu/AliDrive/dev/gitlab/h5-react-project/src/pages/detail'

Could you help me figure out what's wrong here?

kmiyashiro commented 7 years ago

I have this same problem. It seems as if the webpack import plugin registers after the import plugin has already attempted to resolve some paths. If it attempts to resolve them before the plugin has loaded, they do not resolve.

I am using the eslint plugin in Atom and it actually says there are no errors. But when I run the eslint command from the CLI, it does have these errors. This leads me to believe that the plugin works, but maybe it is not enhancing the resolver in time when running from the CLI?

``` ~/Projects/beerfeels-client (webpack2 *)$ DEBUG=eslint-plugin-import:* ./node_modules/.bin/eslint ./app/components/Feel.js eslint-plugin-import:resolver:node Resolving: classnames from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +0ms eslint-plugin-import:resolver:node Resolved to: /Users/kelly/Projects/beerfeels-client/node_modules/classnames/index.js +4ms eslint-plugin-import:utils:ignore ignoring /Users/kelly/Projects/beerfeels-client/node_modules/classnames/index.js, matched pattern /node_modules/ +0ms eslint-plugin-import:ExportMap ignored path due to unambiguous regex or ignore settings: /Users/kelly/Projects/beerfeels-client/node_modules/classnames/index.js +22ms eslint-plugin-import:resolver:node Resolving: moment from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +13ms eslint-plugin-import:resolver:node Resolved to: /Users/kelly/Projects/beerfeels-client/node_modules/moment/src/moment.js +4ms eslint-plugin-import:utils:ignore ignoring /Users/kelly/Projects/beerfeels-client/node_modules/moment/src/moment.js, matched pattern /node_modules/ +34ms eslint-plugin-import:ExportMap ignored path due to unambiguous regex or ignore settings: /Users/kelly/Projects/beerfeels-client/node_modules/moment/src/moment.js +16ms eslint-plugin-import:resolver:node Resolving: react from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +2ms eslint-plugin-import:resolver:node Resolved to: /Users/kelly/Projects/beerfeels-client/node_modules/react/react.js +2ms eslint-plugin-import:utils:ignore ignoring /Users/kelly/Projects/beerfeels-client/node_modules/react/react.js, matched pattern /node_modules/ +29ms eslint-plugin-import:ExportMap ignored path due to unambiguous regex or ignore settings: /Users/kelly/Projects/beerfeels-client/node_modules/react/react.js +25ms eslint-plugin-import:resolver:node Resolving: types from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +2ms eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'types' from '/Users/kelly/Projects/beerfeels-client/app/components' at Function.module.exports [as sync] (/Users/kelly/Projects/beerfeels-client/node_modules/resolve/lib/sync.js:36:11) at Object.exports.resolve (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-import-resolver-node/index.js:19:28) at v2 (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/resolve.js:79:23) at withResolver (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/resolve.js:84:16) at fullResolve (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/resolve.js:101:22) at relative (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/resolve.js:46:10) at resolve (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/resolve.js:172:12) at checkSourceValue (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-plugin-import/lib/rules/no-unresolved.js:29:50) at checkSourceValue (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/moduleVisitor.js:29:5) at EventEmitter.checkSource (/Users/kelly/Projects/beerfeels-client/node_modules/eslint-module-utils/moduleVisitor.js:34:5) +21ms eslint-plugin-import:resolver:webpack Config path from settings: webpack.config.babel.js +64ms eslint-plugin-import:resolver:webpack Config path resolved to: /Users/kelly/Projects/beerfeels-client/webpack.config.babel.js +251ms eslint-plugin-import:resolver:webpack Using config: { entry: { app: '/Users/kelly/Projects/beerfeels-client/app' }, resolve: { root: '/Users/kelly/Projects/beerfeels-client/app', extensions: [ '.js', '.jsx' ], modules: [ '/Users/kelly/Projects/beerfeels-client/app', 'node_modules' ], alias: { beerfeels: '/Users/kelly/Projects/beerfeels-client/app' } }, output: { path: '/Users/kelly/Projects/beerfeels-client/build', filename: 'app.js', publicPath: 'http://localhost:8080/' }, module: { rules: [ [Object], [Object], [Object] ] }, plugins: [ EnvironmentPlugin { keys: [Object], defaultValues: {} }, HtmlWebpackPlugin { options: [Object] }, HotModuleReplacementPlugin { multiStep: undefined, fullBuildTimeout: 200 } ], devServer: { contentBase: '/Users/kelly/Projects/beerfeels-client/build', historyApiFallback: true, hot: true, inline: true, stats: 'errors-only', host: undefined, port: undefined } } +850ms eslint-plugin-import:resolver:webpack enhanced-resolve version: 3.1.0 +3ms eslint-plugin-import:resolver:node Resolving: ../constants/emoji from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +23ms eslint-plugin-import:resolver:node Resolved to: /Users/kelly/Projects/beerfeels-client/app/constants/emoji.js +0ms eslint-plugin-import:resolver:node Resolving: ./Button from: /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +2ms eslint-plugin-import:resolver:node Resolved to: /Users/kelly/Projects/beerfeels-client/app/components/Button.js +0ms eslint-plugin-import:rules:newline-after-import exit processing for /Users/kelly/Projects/beerfeels-client/app/components/Feel.js +191ms eslint-plugin-import:rules:newline-after-import got scope: [ Node { type: 'ImportDeclaration', start: 0, end: 36, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 23, end: 35, loc: [Object], extra: [Object], value: 'classnames', range: [Object], _babelType: 'StringLiteral', raw: '\'classnames\'', parent: [Circular] }, range: [ 0, 36 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ImportDeclaration', start: 37, end: 65, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 56, end: 64, loc: [Object], extra: [Object], value: 'moment', range: [Object], _babelType: 'StringLiteral', raw: '\'moment\'', parent: [Circular] }, range: [ 37, 65 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ImportDeclaration', start: 66, end: 107, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object], [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 99, end: 106, loc: [Object], extra: [Object], value: 'react', range: [Object], _babelType: 'StringLiteral', raw: '\'react\'', parent: [Circular] }, range: [ 66, 107 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ImportDeclaration', start: 108, end: 151, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object], [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 143, end: 150, loc: [Object], extra: [Object], value: 'types', range: [Object], _babelType: 'StringLiteral', raw: '\'types\'', parent: [Circular] }, range: [ 108, 151 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ImportDeclaration', start: 152, end: 230, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object], [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 209, end: 229, loc: [Object], extra: [Object], value: '../constants/emoji', range: [Object], _babelType: 'StringLiteral', raw: '\'../constants/emoji\'', parent: [Circular] }, range: [ 152, 230 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ImportDeclaration', start: 231, end: 261, loc: SourceLocation { start: [Object], end: [Object] }, specifiers: [ [Object] ], importKind: 'value', source: Node { type: 'Literal', start: 250, end: 260, loc: [Object], extra: [Object], value: './Button', range: [Object], _babelType: 'StringLiteral', raw: '\'./Button\'', parent: [Circular] }, range: [ 231, 261 ], _babelType: 'ImportDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ExportDefaultDeclaration', start: 263, end: 1510, loc: SourceLocation { start: [Object], end: [Object] }, declaration: Node { type: 'FunctionDeclaration', start: 278, end: 1510, loc: [Object], id: [Object], generator: false, expression: false, async: false, params: [Object], body: [Object], range: [Object], _babelType: 'FunctionDeclaration', defaults: [], parent: [Circular] }, range: [ 263, 1510 ], _babelType: 'ExportDefaultDeclaration', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ExpressionStatement', start: 1512, end: 1560, loc: SourceLocation { start: [Object], end: [Object] }, expression: Node { type: 'AssignmentExpression', start: 1512, end: 1559, loc: [Object], operator: '=', left: [Object], right: [Object], range: [Object], _babelType: 'AssignmentExpression', parent: [Circular] }, range: [ 1512, 1560 ], _babelType: 'ExpressionStatement', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } }, Node { type: 'ExpressionStatement', start: 1562, end: 1759, loc: SourceLocation { start: [Object], end: [Object] }, expression: Node { type: 'AssignmentExpression', start: 1562, end: 1758, loc: [Object], operator: '=', left: [Object], right: [Object], range: [Object], _babelType: 'AssignmentExpression', parent: [Circular] }, range: [ 1562, 1759 ], _babelType: 'ExpressionStatement', parent: Node { type: 'Program', start: 0, end: 1760, loc: [Object], comments: [], tokens: [Object], range: [Object], sourceType: 'module', directives: undefined, body: [Circular], parent: null } } ] +0ms ```
kmiyashiro commented 7 years ago

After more investigation, it seems that running ./node_modules/.bin/eslint filename actually does work with the webpack resolver. However, setting a script in package.json and running it via yarn run or npm run does not work.

In package.json: "scripts": { "lint": "eslint ./app" } <- yarn run lint will use ./node_modules/.bin/eslint but still does not work.

Even explicitly setting the bin in package.json does not work:

In package.json: "scripts": { "lint": "./node_modules/.bin/eslint ./app" } <- yarn run lint does not work.

Via yarn run lint:

``` ~/Projects/beerfeels-client (webpack2 *)$ yarn run lint yarn run v0.19.1 $ ./node_modules/.bin/eslint ./app/components/Feel.js /Users/kelly/Projects/beerfeels-client/app/components/Feel.js 5:1 error 'types' should be listed in the project's dependencies. Run 'npm i -S types' to add it import/no-extraneous-dependencies 5:36 error Unable to resolve path to module 'types' import/no-unresolved 5:36 error Missing file extension for "types" import/extensions ✖ 3 problems (3 errors, 0 warnings) error Command failed with exit code 1. ```

Running directly:

~/Projects/beerfeels-client (webpack2 *)$ ./node_modules/.bin/eslint ./app/components/Feel.js 
~/Projects/beerfeels-client (webpack2 *)$ 
ljharb commented 7 years ago

That sounds like a bug then - node_modules should never need to be hardcoded anywhere, especially in package.json.

kmiyashiro commented 7 years ago

@ljharb It doesn't need to be hardcoded, it always executes the local eslint bin. It's the fact that the plugin doesn't work because it doesn't resolve modules based on the webpack config either way.

Lint passes: Running ./node_modules/.bin/eslint app from the terminal Lint does not pass: Running yarn run lint with lint being eslint app in package.json. It lints, but the webpack module alias resolving does not work, causing lint errors where it should not. All other eslint plugins work.

benmosher commented 7 years ago

eslint-plugin-import:resolver:node Resolving: ./test.scss

It's using the default node resolver for some files. I suspect some other .eslintrc is getting picked up for some of the files. Strange that .eslintrc resolution would be different between npm run .. and Atom/pure ESlint CLI.

kmiyashiro commented 7 years ago

I'm guessing Atom also just runs the bin directly. The only thing I know of that yarn/npm run does is that it adds node_modules/.bin to $PATH.

ljharb commented 7 years ago

In that case, you should be configuring your Atom to add that to the PATH (or rather it should be doing that for you)

kmiyashiro commented 7 years ago

@ljharb it does use the local eslint copy by default, I do not have eslint installed globally.

RinkAttendant6 commented 6 years ago

I'm encountering this issue now:

Any ideas?

ljharb commented 6 years ago

@RinkAttendant6 sounds like which eslint points to a global install, not a local one. Try npm uninstall -g eslint.

RinkAttendant6 commented 6 years ago

@ljharb Thank you, it is working fine now! I've updated my comment with some more results.

Is there any reason why it doesn't resolve relative to or based on the local ESLint configuration?

ljharb commented 6 years ago

eslint should only be run via an npm run-script or npx; running it by itself doesn't run the local one.