Skip to content

Webpack 3 issue - ExternalModuleFactoryPlugin - 'request' of undefined #705

Closed

Description

@mcrawshaw

Upgrading to webpack 3 generates an error when used with this plugin.

Degrading to webpack 2.x or removing the plugin from config resolves the error.

Note a simular issue here:
#596

Note webpack 3 compatibility issue & PR:
#699
#704

Plugin version:

yarn list v0.24.6
└─ [email protected]
✨  Done in 1.13s.

Webpack version:

yarn list v0.24.6
└─ [email protected]
✨  Done in 1.11s.

Summarised webpack.config (i've tried a blank plugin config - no change):

var webpack = require('webpack');
var path = require('path');
var htmlWebpackPlugin = require('html-webpack-plugin');
var faviconsWebpackPlugin = require('favicons-webpack-plugin');

const root = process.cwd();

module.exports = {
  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.json']
  },
  plugins: [
    ...
    new htmlWebpackPlugin({
      title: 'HiveHub',
      description: 'A mapping platform for software systems',
      filename: 'index.html',
      template: path.join(root, 'src/index.ejs'),
      inject: false,
      appMountId: 'root',
      initialState: 'null',
      initialContent: 'null'
    })
  ],
  module: {
    rules: [
      ...
    ]
  }
};

Full stack dump:

ERROR in   TypeError: Cannot read property 'request' of undefined

  - ExternalModuleFactoryPlugin.js:37 handleExternals
    [metamap]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleF    actoryPlugin.js:37:33

  - ExternalModuleFactoryPlugin.js:46 next
    [metamap]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleF    actoryPlugin.js:46:8

  - ExternalModuleFactoryPlugin.js:59 handleExternals
    [metamap]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleF    actoryPlugin.js:59:7

  - ExternalModuleFactoryPlugin.js:79 ExternalModuleFactoryPlugin    .<anonymous>
    [metamap]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleF    actoryPlugin.js:79:5

  - NormalModuleFactory.js:246 applyPluginsAsyncWaterfall
    [metamap]/[webpack]/lib/NormalModuleFactory.js:246:4

  - Tapable.js:196 NormalModuleFactory.applyPluginsAsyncWaterfall    [metamap]/[webpack]/[tapable]/lib/Tapable.js:196:70

  - NormalModuleFactory.js:230 NormalModuleFactory.create
    [metamap]/[webpack]/lib/NormalModuleFactory.js:230:8

  - Compilation.js:383 Compilation._addModuleChain
    [metamap]/[webpack]/lib/Compilation.js:383:17

  - Compilation.js:465 Compilation.addEntry
    [metamap]/[webpack]/lib/Compilation.js:465:8

  - SingleEntryPlugin.js:22 SingleEntryPlugin.<anonymous>
    [metamap]/[html-webpack-plugin]/[webpack]/lib/SingleEntryPlug    in.js:22:15

  - Tapable.js:229 Compiler.applyPluginsParallel
    [metamap]/[webpack]/[tapable]/lib/Tapable.js:229:14

  - Compiler.js:505
    [metamap]/[webpack]/lib/Compiler.js:505:8

  - Tapable.js:131 Compiler.applyPluginsAsyncSeries
    [metamap]/[webpack]/[tapable]/lib/Tapable.js:131:46

  - Compiler.js:498 Compiler.compile
    [metamap]/[webpack]/lib/Compiler.js:498:7

  - Compiler.js:284 Compiler.runAsChild
    [metamap]/[webpack]/lib/Compiler.js:284:7

  - compiler.js:70
    [metamap]/[html-webpack-plugin]/lib/compiler.js:70:19

Activity

  1. gerardmrk commented on Jun 20, 2017

    @gerardmrk

    Sorry for this useless comment that does not contribute to this issue whatsoever, but just wanted to confirm that I too have this exact same issue with Webpack 3 (just in case this issue is deemed a one-off configuration error on OP's end).

  2. jantimon commented on Jun 20, 2017

    @jantimon
    Owner

    Did you already had time to take a look for the reason?

  3. mcrawshaw commented on Jun 20, 2017

    @mcrawshaw
    Author

    No sorry, would like to help, but not at all sure where to start.

  4. ValeriiVasin commented on Jun 20, 2017

    @ValeriiVasin

    Having the same issue. Seems html-webpack-plugin is not ready yet for webpack 3

  5. mastilver commented on Jun 20, 2017

    @mastilver
    Collaborator

    @hulkish @yuffiy @yveskaufmann Do you think you can help here as it sounds like you managed to make webpack@3 working with html-webpack-plugin?

  6. mastilver commented on Jun 20, 2017

    @mastilver
    Collaborator

    Do you think any of you can provide a repo to reproduce it?

    On my project I only get a warning on npm install but except that everything is running fine...

  7. HairyRabbit commented on Jun 20, 2017

    @HairyRabbit
    Contributor

    @mastilver ❤️ Change dir to node_modules/html-webpack-plugin then run npm install webpack extract-text-webpack-plugin maybe works fine.

    Or use my forked repo until the PR merged.

    { 
      "html-webpack-plugin": "https://github.com/Re-Rabbit/html-webpack-plugin.git" 
    }
  8. mattlewis92 commented on Jun 20, 2017

    @mattlewis92

    I'm getting this as well, it seems to be a bug with yarn whereby a dependency (webpack-stream) has a hard dependency on webpack 1 and it's getting copied into other dependencies that depend on webpack as peer dependencies:

    Matts-MacBook-Pro:ssi-webapp mattlewis$ npm ls webpack
    ssi-webapp@ /Users/mattlewis/Code/socialsignin/ssi-webapp
    ├─┬ [email protected]
    │ └── [email protected]  extraneous
    ├─┬ [email protected]
    │ └─┬ [email protected]
    │   └── [email protected]  extraneous
    ├─┬ [email protected]
    │ └── [email protected]  extraneous
    ├─┬ [email protected]
    │ └── [email protected]  extraneous
    └─┬ [email protected]
      └── [email protected] 
    

    The only solution I've found so far is to switch from yarn to npm5

  9. joseds commented on Jun 20, 2017

    @joseds

    I can confirm this, I also switched temporarily from yarn to npm, sorry, don't have the time to investigate further right now.

  10. mastilver commented on Jun 20, 2017

    @mastilver
    Collaborator

    @mattlewis92 @joseds To clarify myself, the warning I got from npm/yarn is expected. (as the peerDependency doesn't allow webpack@3 yet)

    About the issue @mcrawshaw raises: I can't reproduce it on my project

  11. mattlewis92 commented on Jun 20, 2017

    @mattlewis92

    @mastilver I was referring to how to reproduce the error with ERROR in TypeError: Cannot read property 'request' of undefined. When there is a dependency that depends on webpack v1 (as an actual dependency not a peer dependency) then yarn is putting webpack v1 as a dependency of html-webpack-plugin which is throwing then throwing that error as its requiring code from webpack v1, but then trying to use it with a webpack v3 instance.

    tl;dr it's an issue with yarn, updating the peer dependency to allow webpack v3 might fix the issue.

  12. mcrawshaw commented on Jun 20, 2017

    @mcrawshaw
    Author

    Yep, I can confirm, it's a packaging issue. Using npm 5.0.3 resolves my issue.

    My npm list looks similar to you @mattlewis92.

    Mark.

  13. damianobarbati commented on Jun 21, 2017

    @damianobarbati

    is a fix coming any soon? looks like a trivial change right? thanks guys!

  14. ErikFontanel commented on Jun 21, 2017

    @ErikFontanel

    I had the same issue after upgrading to Webpack 3. And I too can confirm using npm 5.0.3 instead of yarn fixes the issue.

  15. mastilver commented on Jun 21, 2017

    @mastilver
    Collaborator

    @damianobarbati I think are going to hold off until extract-text-webpack-plugin@3 is out, we don't want to release something unless we are 100% sure it's not going to break any of the features we currently support

    Until that is done you can use directly either: #706 or #707

    @jantimon Can you confirm this is the right approach and I'm not saying BS? ;)

  16. damianobarbati commented on Jun 24, 2017

    @damianobarbati

    @mastilver do you think this is going to happen any soon?

  17. mcrawshaw commented on Jun 25, 2017

    @mcrawshaw
    Author

    Can confirm as resolved.

  18. smoliakov commented on Aug 4, 2017

    @smoliakov

    Unfortunately, the same issue, after updating to:

    "webpack": "3.4.1",
    "html-webpack-plugin": "2.30.1",
    "html-loader": "0.5.0",
    "webpack-dev-server": "2.6.1"
    

    Output (yarn start, "start": "webpack-dev-server --inline --hot")

    TypeError: Cannot read property 'request' of undefined
    - ExternalModuleFactoryPlugin.js:37 handleExternals
      [likeometer]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleFactoryPlugin    .js:37:33
      
    - ExternalModuleFactoryPlugin.js:46 next
      [likeometer]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleFactoryPlugin    .js:46:8
    

    Node modules reinstall didn't help.
    NPM 5.3.0 also didn't work.

  19. mastilver commented on Aug 4, 2017

    @mastilver
    Collaborator

    @AlexeySmolyakov Did you check: #683 (comment)

  20. smoliakov commented on Aug 4, 2017

    @smoliakov

    @mastilver thank you so much!
    Removing yarn.lock is the key.

  21. martinpinto commented on Dec 29, 2017

    @martinpinto

    I can confirm that updating
    "webpack": "3.4.1", "html-webpack-plugin": "2.30.1", "html-loader": "0.5.0", "webpack-dev-server": "2.6.1"
    to the latest versions (and explicitly adding them to package.json) fixes the problem. Why do every npm i have to lead to breaking changes? Removing all "~"'sand "^"'s from my package.json!

  22. lock commented on May 31, 2018

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  23. locked as resolved and limited conversation to collaborators on May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions