New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack@^2.1.0-beta.23 throws "Configuration has an unknown property 'eslint'" #113

Closed
alexsunxl opened this Issue Sep 20, 2016 · 21 comments

Comments

Projects
None yet
8 participants
@alexsunxl
Copy link
Contributor

alexsunxl commented Sep 20, 2016

webpack v2.1.0-beta.23 is not support setting 'eslint' in the exports.

module.exports = { eslint: { configFile: 'path/.eslintrc' } }

error print

how can i set the eslint config file path.

@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

Your picture is not accessible, I get a "not found".

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 20, 2016

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

  • configuration has an unknown property 'eslint'. These properties are valid:
    object { amd?, bail?, cache?, context?, devServer?, devtool?, entry, externals?, loader?, module?, name?, dependencies?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

Well that's a breaking change... Semver is not really respected...
So latest webpack version validate all options. Ouch. @TheLarkInn @sokra are you aware that some loaders use this pattern to pass options? I know more than one that use this...
Maybe you could expose an API so we can add some entries...? Or maybe know query accept more than json?

@alexsunxl any idea where would you like to get your options?

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 20, 2016

I think add path to rules's query may be awesome.

webpack.config.js

module.exports = { 
  ...
  module: { 
    rules: [ 
        {
            enforce: 'left',
            test: /\.js$/,
            loader: 'eslint-loader',
            query: {
               configFile: './.eslintrc.js'
            },
        },
       ...
    ]
  }
  ...
}

And I try to change code in my locale, can I PR after finish?

@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

query should already be supported.

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 20, 2016

I see

  var config = assign(
    // loader defaults
    {
      formatter: require("eslint/lib/formatters/stylish"),
    },
    // user defaults
    this.options.eslint || {},
    // loader query string
    loaderUtils.parseQuery(this.query)
  )

but it is not working. I don't know why
eslint not read my eslintrc

@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

Maybe try with configFile: __dirname + '/.eslintrc.js'?

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 20, 2016

Finally I find the mistake is that the 'enforce' shoule be 'right' to instead of preLoaders.
Thank you so much ~~

module.exports = { 
  ...
  module: { 
    rules: [ 
        {
            enforce: 'right',
            loader: 'eslint-loader',
            query: {
               configFile: 'path'
            },
        },
       ...
    ]
  }
  ...
}
@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

The current official solution with webpack@2.1 beta23 seems to be

Change this

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'foo.chunk.js',
    path: './dist'
  },
  eslint: {
    /* your eslint loader config */
  }
}

to this

const webpack = require('webpack');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'foo.chunk.js',
    path: './dist'
  },
  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        eslint: {
          /* your eslint loader config */
        }
      }
    })
  ]
}
@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 20, 2016

I see , 👍

@alexsunxl alexsunxl closed this Sep 20, 2016

@MoOx

This comment has been minimized.

Copy link
Member

MoOx commented Sep 20, 2016

Reopening until I push a notice in the README

@MoOx MoOx reopened this Sep 20, 2016

@MoOx MoOx changed the title webpack beta.23, configuration has an unknown property 'eslint' webpack@^2.1.0-beta.23 throws "Configuration has an unknown property 'eslint'" Sep 20, 2016

@eriknyk

This comment has been minimized.

Copy link

eriknyk commented Sep 23, 2016

not sure what is the complete solution,
still using preLoaders or not?, use new webpack.LoaderOptionsPlugin(), instead eslint section,
still it is not working for me, using webpack 2.1.0-beta.25

Regards.

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 23, 2016

@eriknyk
'preLoaders' is no longer use.

module.exports = { 
  ...
  module: { 
    // loaders or rules is all the same
    loaders: [ 
        {
            enforce: 'right',
            loader: 'eslint-loader',
            // query is same with the [new webpack.LoaderOptionsPlugin()]
            query: {
               configFile: 'path'
            },
        },
       ...
    ]
  }
  ...
}
@eriknyk

This comment has been minimized.

Copy link

eriknyk commented Sep 23, 2016

thank you @alexsunxl I will try it.

@alexsunxl

This comment has been minimized.

Copy link
Contributor Author

alexsunxl commented Sep 23, 2016

@eriknyk in webpack@2.1.0-beta.25 [enforce: 'right'] should be [enforce: 'pre']
see the webpack v2.1.0-beta.24

@alexsunxl alexsunxl referenced this issue Sep 23, 2016

Merged

Update README #115

@eriknyk

This comment has been minimized.

Copy link

eriknyk commented Sep 23, 2016

it worked, thank you a lot @alexsunxl

@johnthecat

This comment has been minimized.

Copy link

johnthecat commented Oct 1, 2016

Hi, can't migrate to beta 25, because webpack throws error
configuration has an unknown property 'failOnError'
It also doesn't work after webpack.LoaderOptionsPlugin used.
Can you help me?

@kristianmandrup

This comment has been minimized.

Copy link

kristianmandrup commented Nov 1, 2016

Please update Readme with a section for Webpack 2.1 beta25+ configuration :)
I'm using this setup which works:

  module: {
    rules: [
      {
        enforce: 'pre',
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'eslint'
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          babelrc: true,
          cacheDirectory: true
        }
      }
    ]
  }
@ClementParis016

This comment has been minimized.

Copy link

ClementParis016 commented Nov 6, 2016

I can't see what the proper use of webpack.LoaderOptionsPlugin should be, since this works:

{
    test: /\.js$/,
    include: [path.join(__dirname, 'src/app')],
    loader: 'eslint-loader',
    enforce: 'pre',
    query: {
       configFile: path.join(__dirname, '.eslintrc')
     },
},

but this doesn't (falls back to default eslint config):

 plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        eslint: {
          configFile: path.join(__dirname, '.eslintrc')
        }
      }
    })
]
@hinok

This comment has been minimized.

Copy link
Contributor

hinok commented Dec 5, 2016

@ClementParis016 I think that you've missed test: {...} so it should be

 plugins: [
    new webpack.LoaderOptionsPlugin({
      test: /\.js$/,
      options: {
        eslint: {
          configFile: path.join(__dirname, '.eslintrc')
        }
      }
    })
]

Works for me on webpack 2.1.0-beta.27

@barraponto

This comment has been minimized.

Copy link
Contributor

barraponto commented Jan 8, 2017

This is from a working configuration:

/* eslint-env node */
const path = require('path');
module.exports = {
  // entry, output, other top-level options ...
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        enforce: 'pre',
        use: [{loader: 'eslint-loader'}],
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {presets: [['es2015', {modules: false}]]},
          },
        ],
      },
    ],
  },
  // no need for plugins
};

Note that the official Webpack 2 documentation no longer supports loaders or query, and using enfore: pre requires a separate rule (although you could just leave eslint-loader as the last rule, since they are applied in reverse order).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment