webpack-contrib / eslint-loader

[DEPRECATED] A ESlint loader for webpack
MIT License
1.06k stars 121 forks source link

Cannot read property 'getFormatter' of undefined #331

Closed XeniaSiskaki closed 4 years ago

XeniaSiskaki commented 4 years ago

Expected Behavior

Lint project without errors

Actual Behavior

The loader fails with the following error:

Module build failed (from ./node_modules/eslint-loader/dist/cjs.js):
TypeError: Cannot read property 'getFormatter' of undefined
    at getFormatter (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/getOptions.js:52:20)
    at getOptions (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/getOptions.js:30:23)
    at Object.loader (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/index.js:17:43)

Code - webpack rule

module: {
    rules: [{
        test: /\.tsx?$/,
        use: [
            {
                loader: 'awesome-typescript-loader',
                options: {
                    configFileName: tsConfigFile
                }
            },
            {
                loader: 'eslint-loader',
                options: {
                    fix: true,
                    eslintPath: eslintrcFile,
                    emitError: true,
                    emitWarning: true
                }
            }
        ]
    }]
}

I've read through some issues saying that the loader wasn't compatible with eslint v6 but they are all now closed so I can only assume that compatibility was added. I tried adding the formatter explicitly with

formatter: require('eslint').CLIEngine.getFormatter('stylish')

but then I get a different error

Module build failed (from ./node_modules/eslint-loader/dist/cjs.js):
TypeError: CLIEngine is not a constructor
    at createEngine (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/createEngine.js:22:21)
    at new Linter (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/Linter.js:30:35)
    at Object.loader (/home/devel/sandbox/web-client/node_modules/eslint-loader/dist/index.js:18:18)

Let me know if you need more information

XeniaSiskaki commented 4 years ago

Adding the following option seems to solve the issue:

eslintPath: 'eslint'

It still seems this is a bug in the loader, as printing the options without providing the eslintPath explicitly, the path points to the path of .eslintrc.json and of course this doesn't export a CLIEngine

XeniaSiskaki commented 4 years ago

I'm sorry, I was misusing the eslintPath config option. I've mistaken it with the configFile