Skip to content

Fix bug where compiler is not accessible by computeContextPath #299

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

Merged
merged 1 commit into from
Jun 12, 2019
Merged

Fix bug where compiler is not accessible by computeContextPath #299

merged 1 commit into from
Jun 12, 2019

Conversation

DASPRiD
Copy link
Contributor

@DASPRiD DASPRiD commented Jun 12, 2019

I'm not 100% certain why this was causing a problem. I did some debugging and it turned out that computeContextPath as an arrow function had not the same this context. When changing it to a normal function, it works as expected.

Fixes #267

For me this bug was happening in conjunction with serverless-webpack and having individual packaging enabled.

@johnnyreilly
Copy link
Member

Awesome work! Would you be able to add a test as well so we don't regress this in future please? (I've an idea we've broken this previously 😭)

@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 12, 2019

Well, the thing is, I have no idea how to reproduce the problem in an isolated test. I mean, the existing tests don't break, so I'm really not sure about the cause of this.

johnnyreilly
johnnyreilly previously approved these changes Jun 12, 2019
Copy link
Member

@johnnyreilly johnnyreilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind - let's get this anyways 😄

@johnnyreilly
Copy link
Member

I'd ❤️ to merge this but it doesn't meet our commit guidelines: https://github.com/Realytics/fork-ts-checker-webpack-plugin/blob/master/CONTRIBUTING.md#examples

We're using semantic-release - can you fix up using this convention instead please?

@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 12, 2019

Sure, done.

@phryneas
Copy link
Contributor

Not questioning this PR, (let's merge it as soon as the CI is through), but out of general curiousity, because I would love to understand the underlying problem:

What is your setup? Are you also using grunt-webpack like in #267?

@phryneas phryneas merged commit 489dc89 into TypeStrong:master Jun 12, 2019
@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 12, 2019

@phryneas No, as I wrote above, I am using serverless with serverless-webpack and individual packaging enabled.

@phryneas
Copy link
Contributor

phryneas commented Jun 12, 2019

@phryneas No, as I wrote above, I am using serverless with serverless-webpack and individual packaging enabled.

Oh, sorry, somehow overread that :) Thanks 👍

So it seems this happens with multi-webpack setups.

@piotr-oles
Copy link
Collaborator

🎉 This PR is included in version 1.3.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@phryneas
Copy link
Contributor

So what I believe happens is this:

serverless-webpack creates multiple instances of webpack and all those instances are just getting clones of the original configuration. If this is really the place I am suspecting, they are just calling cloneDeep on the config, which also creates a clone of the fork-ts-checker-webpack-plugin instance.
And then we are getting the bug: plugin.apply is called on the clone, but the method that was fixed with this PR is a bound arrow function, so this is still pointing to the original plugin, not to the clone. And that one is never initialized (and if it were, it would point at a wrong compiler).

@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 12, 2019

Wow, that actually makes sense. Good find!

@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 12, 2019

@phryneas Any idea if a test for that can be written?

@phryneas
Copy link
Contributor

phryneas commented Jun 12, 2019

@DASPRiD Phew... I guess it can, at least partially.

Short analysis: this type of bug can only occur in the index.ts, in the class ForkTsCheckerWebpackPlugin itself. Everything else happens in a forked process, and that can't be incluenced by any such type of cloning.

Instantiating the plugin, deepCloning it and then just calling all methods won't do the trick though (as all these methods are highly interconnected) - and especially it will most likely not catch any new bugs introduced in the future.

The only thing I would see here is to create an integration test and in the prepareWebpackConfig callback of the createCompiler helper replace the plugin with a deepCloned copy. Then just run the plugin and see if it works or fails.

Something like this test could be a starting point, with the modifications I described above.

Would you be willing to give it a try? :)

@DASPRiD
Copy link
Contributor Author

DASPRiD commented Jun 13, 2019

@phryneas uff, I'm not too much into all the guts of webpack or this plugin, so I'd rather leave that to you, as you seem to definitely have a better understanding of this :)

@johnnyreilly
Copy link
Member

Once again I'm astounded by @phryneas ability to find, diagnose and understand an esotoric problem in the codebase... And not only that he documents it effectively thus communicating what he's learned to anyone that cares to read. Props! ♥️🥰

@phryneas
Copy link
Contributor

@phryneas uff, I'm not too much into all the guts of webpack or this plugin, so I'd rather leave that to you, as you seem to definitely have a better understanding of this :)

@DASPRiD Feared so ^^.
I'll put it on my TODO list, but it can take some time until I get around to that.
If you change your mind and wanna give it a try before that, just do :) Can't really go wrong ;)

@madebyherzblut
Copy link

I am still having some trouble with this. Sometimes, this.compiler in computeContextPath is still undefined:

TypeError: Cannot read property 'compiler' of undefined
    at computeContextPath ([REDACTED]]/launchpad/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:207:27)
    at Array.map (<anonymous>)
    at ForkTsCheckerWebpackPlugin.apply ([REDACTED]]/launchpad/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:149:34)
    at webpack ([REDACTED]]/launchpad/node_modules/webpack/lib/webpack.js:47:13)
    at compile ([REDACTED]]/launchpad/packages/launchpad/src/scripts/start.js:72:16)
    at main ([REDACTED]]/launchpad/packages/launchpad/src/scripts/start.js:33:26)

The problem is fixed when I add a .bind(this) to this.watchPaths = this.watch.map(this.computeContextPath); (L283). The webpack configuration itself can be seen here–as far as I am concerned there is no cloning involved.

@phryneas
Copy link
Contributor

@madebyherzblut you're absolutely right, that's a follow-up error that now occurs because that method is not implicitly bound any more sigh
I'm gonna look into that this evening.

phryneas added a commit to phryneas/fork-ts-checker-webpack-plugin that referenced this pull request Jun 13, 2019
phryneas added a commit to phryneas/fork-ts-checker-webpack-plugin that referenced this pull request Jun 13, 2019
phryneas added a commit to phryneas/fork-ts-checker-webpack-plugin that referenced this pull request Jun 13, 2019
phryneas added a commit to phryneas/fork-ts-checker-webpack-plugin that referenced this pull request Jun 13, 2019
@phryneas
Copy link
Contributor

While I was at it writing a regression test für #300, I added one for this ticket, too :)

phryneas added a commit to phryneas/fork-ts-checker-webpack-plugin that referenced this pull request Jun 13, 2019
phryneas added a commit that referenced this pull request Jun 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'options' of undefined
5 participants