Skip to content
This repository has been archived by the owner on Jul 18, 2019. It is now read-only.

jshint-loader not working with webpack 4 #50

Open
Harrix opened this issue Mar 10, 2018 · 13 comments
Open

jshint-loader not working with webpack 4 #50

Harrix opened this issue Mar 10, 2018 · 13 comments

Comments

@Harrix
Copy link

Harrix commented Mar 10, 2018

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' }]
    },
@donkeybrains
Copy link

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];
}
}
}

@arizvisa
Copy link

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
Copy link

Ugh, I fucking hate javascript.

@arizvisa
Copy link

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

@arizvisa
Copy link

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.

@shellscape
Copy link
Contributor

shellscape commented Apr 8, 2018

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

@arizvisa dial back the language please.

@AtanuMandal
Copy link

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",

@shellscape
Copy link
Contributor

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

arizvisa added a commit to arizvisa/jshint-loader that referenced this issue May 8, 2018
…-guide-for-plugins-loaders-20a79b927202 states that webpack4 has deprecated this.options in favor of this.query. Closes issue webpack-contrib#50.
@russelyang
Copy link

russelyang commented May 12, 2018

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];
		}
	} 

@arizvisa
Copy link

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

@ghost
Copy link

ghost commented Sep 8, 2018

Still not working :/

@arizvisa
Copy link

arizvisa commented Sep 9, 2018

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

@arizvisa
Copy link

arizvisa commented Sep 9, 2018

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" (#51 (comment)) 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants