Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.
This repository was 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

Description

@drwpow

(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

Activity

  1. michael-ciniawsky commented on Dec 5, 2017

    @michael-ciniawsky
    Member

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

  2. changed the title [-]webpack 4.0.0-alpha.0 breaking changes[/-] [+][webpack v4.0.0-alpha.0] `this.context` => `this.rootContext` (Breaking Change)[/+] on Dec 5, 2017
  3. drwpow commented on Dec 5, 2017

    @drwpow
    Author

    @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 ({}).

  4. michael-ciniawsky commented on Dec 5, 2017

    @michael-ciniawsky
    Member

    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;
  5. drwpow commented on Dec 5, 2017

    @drwpow
    Author

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

  6. michael-ciniawsky commented on Dec 5, 2017

    @michael-ciniawsky
    Member

    @DangoDev Thx for testing that out :)

  7. Wisedemic commented on May 26, 2018

    @Wisedemic
    - 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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions