Configuring library as external in webpack does not work like expected with UMD as libraryTarget

Do you want to request a feature or report a bug?
I assume this could be a bug.

What is the current behavior?
I want to build my own JavaScript library and register it under an already existing namespace (“OCA” – in this particular case). Therefore I use webpack 2 and the libraryTarget: umd to register the output under “OCA.Ocr” (my library is named “Ocr”). This works like intended, but when it comes to the point that I want to use for example underscorejs as a library which will be included in the html later, I cannot get it to work. I followed the webpack configuration documentation and it says that the externals configuration option should be the way to go. But if I use it like stated in the documentation, the underscore library in this case is not defined. I also checked, that the library is available in the global namespace and the file gets loaded before my webpack bundle.

If the current behavior is a bug, please provide the steps to reproduce.
my webpack.config.js
my typescript code
webpack bundle

Firefox says:

TypeError: underscore_1.default is undefined

What is the expected behavior?
No TypeError should be thrown and the underscorejs (_) library should be also available for the library bundled with webpacka as an external. (Like stated in the documentation)

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Webpack Version: 2.5.0
Node: 6.10.2
OS: Debian Jessie
Browser: Firefox ESR 45.9.0

Also related is my stackoverflow question as I actually don’t know if this is my fault or if this is a bug. (Maybe it would be at least nice to give more information regarding such use case in the documentation)

Author: Fantashit

1 thought on “Configuring library as external in webpack does not work like expected with UMD as libraryTarget

  1. Any update?

    I am also facing the same issue with AMD libraryTarget in webpack version 3.8.1 and 3.10.0.

Comments are closed.