jshint-loader icon indicating copy to clipboard operation
jshint-loader copied to clipboard

jshint-loader not working with webpack 4

Open Harrix opened this issue 6 years ago • 13 comments

In webpack 4 in the presence of packages jslint and jshint-loader error on the similarity of such:

ERROR in ./src/js/index.js
Module build failed: TypeError: Cannot read property 'jshint' of undefined
    at Object.jsHint (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\jshint-loader\index.js:63:18)
    at Object.<anonymous> (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\jshint-loader\index.js:149:11)
    at Object.<anonymous> (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\jshint-loader\index.js:40:12)
    at respond (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\rcloader\index.js:68:7)
    at respond (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\rcfinder\index.js:140:7)
    at next (D:\Harrix\GitHub\Harrix-HTML-Template\node_modules\rcfinder\index.js:164:16)
    at process._tickCallback (internal/process/next_tick.js:112:11)

Example of rule:

{ // this is both for prod and dev environments
      enforce: 'pre',
      test: /\.js$/,
      include: path.resolve(__dirname, 'src'),
      use: [{ loader: 'jshint-loader' }]
    },

Harrix avatar Mar 10 '18 07:03 Harrix

Even with a .jshintrc populated and in the root of the project the node_module jshint index,js file has the this.options coming in as undefined. Boom exception. Have tried adding the option to the web.congig.js loader still same issue.

I use the Rules:

I added a console.log to the index.js file in jshint: { console.log("Warning this.options is undefined."); } else{ if(this.options.jshint) { for(var name in this.options.jshint) { options[name] = this.options.jshint[name]; } } }

donkeybrains avatar Mar 14 '18 21:03 donkeybrains

Hey guys, this link talks about how this.options was deprecated and what to switch it to: https://medium.com/webpack/webpack-4-migration-guide-for-plugins-loaders-20a79b927202

arizvisa avatar Mar 22 '18 16:03 arizvisa

Ugh, I fucking hate javascript.

arizvisa avatar Mar 22 '18 17:03 arizvisa

I created a PR, #51 which closes this shit.

arizvisa avatar Mar 22 '18 17:03 arizvisa

If any of you guys need the fix for this before they merge the PR, you can use https://github.com/arizvisa/jshint-loader#webpack-4 in your packages for npm.

arizvisa avatar Mar 24 '18 18:03 arizvisa

We're working on getting this repo up to date. Hang tight.

@arizvisa dial back the language please.

shellscape avatar Apr 08 '18 13:04 shellscape

did anyone find a solution for this? I am having the exact same issue with "jshint": "^2.9.5", "jshint-loader": "^0.8.4", "webpack": "^4.5.0",

AtanuMandal avatar Apr 16 '18 18:04 AtanuMandal

@AtanuMandal #53 and #51 address this. please take a look at Pull Requests next time around before dropping a followup comment

shellscape avatar Apr 16 '18 19:04 shellscape

Current fix is risking, it will break old webpack 3 if user choose use options in webpack config. a better fix just simply do this.

	if(this.options && this.options.jshint) {
		for(var name in this.options.jshint) {
			options[name] = this.options.jshint[name];
		}
	} 

russelyang avatar May 12 '18 00:05 russelyang

@russelyang (or anybody), mind creating a PR? My PR at #51 seems to have gone stale due to issues with the cla signature.

arizvisa avatar Jun 20 '18 19:06 arizvisa

Still not working :/

ghost avatar Sep 08 '18 18:09 ghost

@ybaruchel, you can use https://github.com/arizvisa/jshint-loader#webpack-4 in your packages for npm to get it working.

arizvisa avatar Sep 09 '18 00:09 arizvisa

actually, once PR #55 is merged, my fix can be re-opened and rebased on top of it. The reason my PR wasn't merged is that despite my PR being a single-line fix, I was "given the honor" (https://github.com/webpack-contrib/jshint-loader/pull/51#issuecomment-387597209) of having to update the versions of the other packages which also included refactoring a bunch of other code that was completely unrelated to my initial fix. this required a lot more more work than i was willing to put in.

so, rather than committing more time to refactor the other unrelated parts in jshint-loader to accommodate the new package versions and pass these tests, I chose to close the PR instead as I can just use my forked repo with the webpack-4 fixes.

but since it looks like the author of PR #55 actually went through the required refactoring that I didn't care to. I should be able to just rebase my fix on top of it and then things should be good to go once it gets merged.

arizvisa avatar Sep 09 '18 01:09 arizvisa