Skip to content
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

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

Closed
mcrawshaw opened this issue Jun 19, 2017 · 22 comments · Fixed by #707
Closed

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

mcrawshaw opened this issue Jun 19, 2017 · 22 comments · Fixed by #707

Comments

@mcrawshaw
Copy link

mcrawshaw commented Jun 19, 2017

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
└─ html-webpack-plugin@2.28.0
✨  Done in 1.13s.

Webpack version:

yarn list v0.24.6
└─ webpack@3.0.0
✨  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
@gerardmrk
Copy link

gerardmrk commented Jun 20, 2017

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).

@jantimon
Copy link
Owner

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

@mcrawshaw
Copy link
Author

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

@ValeriiVasin
Copy link

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

@mastilver
Copy link
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?

@mastilver
Copy link
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...

@HairyRabbit
Copy link
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" 
}

@mattlewis92
Copy link

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
├─┬ html-webpack-plugin@2.28.0
│ └── webpack@1.15.0  extraneous
├─┬ karma-webpack@2.0.3
│ └─┬ webpack-dev-middleware@1.10.2
│   └── webpack@1.15.0  extraneous
├─┬ script-ext-html-webpack-plugin@1.8.1
│ └── webpack@1.15.0  extraneous
├─┬ webpack-karma-die-hard@1.0.4
│ └── webpack@1.15.0  extraneous
└─┬ webpack-stream@3.2.0
  └── webpack@1.15.0 

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

@joseds
Copy link

joseds commented Jun 20, 2017

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

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

@mattlewis92
Copy link

@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.

@mcrawshaw
Copy link
Author

mcrawshaw commented Jun 20, 2017

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.

@damianobarbati
Copy link

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

@ErikFontanel
Copy link

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.

@mastilver
Copy link
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? ;)

@damianobarbati
Copy link

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

@mcrawshaw
Copy link
Author

Can confirm as resolved.

@smoliakov
Copy link

smoliakov commented Aug 4, 2017

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.

@mastilver
Copy link
Collaborator

@AlexeySmolyakov Did you check: #683 (comment)

@smoliakov
Copy link

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

@martinpinto
Copy link

martinpinto commented Dec 29, 2017

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!

@lock
Copy link

lock bot commented May 31, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.