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

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

Closed
janis91 opened this issue May 5, 2017 · 11 comments

Comments

@janis91
Copy link

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)

@sokra
Copy link
Member

sokra commented May 6, 2017

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

@janis91
Copy link
Author

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.

@82antu
Copy link

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

@pathikdevani
Copy link

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.

@OlegZavrazhin
Copy link

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

@finom
Copy link

finom commented Jan 20, 2019

Any news?

@psmadhav
Copy link

psmadhav commented Sep 6, 2019

I am also stuck here!

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@alexander-akait
Copy link
Member

Fixed in webpack@5, now we use __importDefault helper, so .default is supported, anyway feel free to feedback

@webpack-bot
Copy link
Contributor

For maintainers only:

  • webpack-4
  • webpack-5
  • bug
  • critical-bug
  • enhancement
  • documentation
  • performance
  • dependencies
  • question

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

No branches or pull requests

9 participants