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

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

janis91 opened this Issue May 5, 2017 · 5 comments


None yet
5 participants

janis91 commented May 5, 2017

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)


This comment has been minimized.


sokra commented May 6, 2017

Yep, this looks like a bug. webpack doesn't generate the CJS harmony interop layer for externals.


This comment has been minimized.

janis91 commented May 9, 2017

If you give me any hint where to look and how to pass this problem, I could try to fix it and contribute.


This comment has been minimized.

82antu commented Aug 17, 2017

Same Issue, Here, (more or less);

I have a custom umd library (mylib) made by myself (bundled with webpack, of course); when I try to consume it in my application (bundled also with webpack) as "externals", it simply doesn't work.

The output of application (app.js)

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("mylib"));
else if(typeof define === 'function' && define.amd)
define(["mylib"], factory);
else {
var a = typeof exports === 'object' ? factory(require("mylib")) : factory(root["mylib"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
})(this, function(WEBPACK_EXTERNAL_MODULE_364) {
return /******/ (function(modules) { // webpackBootstrap

always has WEBPACK_EXTERNAL_MODULE_364 as undefined


This comment has been minimized.

pathikdevani commented Feb 6, 2018

Any update?

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


This comment has been minimized.

OlegZavrazhin commented Jul 27, 2018

It's one of most important thing (library:) I want to use in webpack 3.12.0.
Any chance to have it soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment