Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

[webpack v4.0.0-alpha.0] this.context => this.rootContext (Breaking Change) #233

Closed
drwpow opened this issue Dec 4, 2017 · 6 comments
Closed

Comments

@drwpow
Copy link

drwpow commented Dec 4, 2017

(from webpack#6064)

Running webpack with 4.0.0-alpha.0 results in the following error, one per file:

ERROR in ./assets/images/icons/search.svg
Module build failed: TypeError: Cannot read property 'context' of undefined
    at Object.loader (/Users/drew/Sites/my-site/node_modules/file-loader/dist/index.js:34:49)
 @ ./styles.sass 6:40863-40906
@michael-ciniawsky
Copy link
Member

Could you please try the suggestion in webpack/webpack#6064 (comment) using rootContextinstead of context and provide the results/errors here ?

@michael-ciniawsky michael-ciniawsky changed the title webpack 4.0.0-alpha.0 breaking changes [webpack v4.0.0-alpha.0] this.context => this.rootContext (Breaking Change) Dec 5, 2017
@drwpow
Copy link
Author

drwpow commented Dec 5, 2017

@michael-ciniawsky Not sure if it’s what you asked, but I tried changing context: to rootContext: in the webpack config but that obviously resulted in a configuration error.

So then I assumed you meant file-loader, and I went to index.js:34 and made the following change:

-  const context = options.context || this.options.context;
+  const context = options.context;

And it successfully built and emitted files.

At least in my instance, this.options wasn’t defined, and options was just an empty object ({}).

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Dec 5, 2017

Not sure if it’s what you asked, but I tried changing context: to rootContext: in the webpack config but that obviously resulted in a configuration error.

You mean aValidationError in particular here ? :) That's to be expected then, but the change in question (this.options.context => this.rootContext) needs to be made elsewhere. Could you try

- const context = options.context || this.options.context;
+ const context = options.context || this.rootContext;

@drwpow
Copy link
Author

drwpow commented Dec 5, 2017

@michael-ciniawsky Yup! That works for me—this.rootContext correctly returns the context. @TheLarkInn’s change in #234 seems to work for me.

@michael-ciniawsky
Copy link
Member

@DangoDev Thx for testing that out :)

@Wisedemic
Copy link

- var context = options.context || this.options.context;
+ const context = options.context || this.rootContext;

This error is still happening! The above code fixed it for me.

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

No branches or pull requests

4 participants