Questions tagged [umd]

Universal Module Definition (UMD) is an API for JavaScript modules that are capable of working in browsers, on the server, or elsewhere.

Universal Module Definition (UMD) is an API for JavaScript modules that are capable of working in browsers, on the server, or elsewhere.

The UMD pattern typically attempts to offer compatibility with the most popular script loaders of the day (RequireJS, CommonJS, and others). In many cases it uses AMD as a base, with special-casing added to handle CommonJS compatibility.

See the GitHub repo for more information.

198 questions
3
votes
1 answer

How to import a custom UMD module in a Webpack 4 project

I am developping a library that needs to work in both node and a react app. I use a webpack 4 project that generates a UMD module, but I have a problem when I try to import it in a simple webpack project. When I use import lib from 'myLib'; lib is…
Evilgalith
  • 31
  • 4
3
votes
2 answers

iife along es6 module

I have a library that is basically an IIFE that sets a global variable, and clients are supposed to operate on said variable. So, in module.js, I have something like window.myModule = (function(){ ... return { foo: foo, bar:…
user4052054
  • 395
  • 1
  • 6
  • 22
3
votes
0 answers

ng-packagr and shared modules

I'm trying to package a module X with dependencies to Y using ng-pacakgr. X and Y have services and components. App/module structure is : ModuleX imports ModuleY X.forRoot() provides ServiceY. ServiceY is used in AppModule and ModuleX. AppModule…
Patrice
  • 1,404
  • 1
  • 14
  • 27
3
votes
0 answers

requireJS optimizer - combining two anonymous modules into one combined.js file

I am trying to combine two require amd modules into one combined.js javascript file using RequireJS optimizer. **This question is not the same than this one: Mismatched anonymous define() module where there is not a solution or detailed explanation…
xtrm
  • 966
  • 9
  • 22
3
votes
2 answers

Typescript error Cannot find module 'typescript-Collections' when changing the module to "umd" or "amd" in tsconfig.json

I am using VS17 Enterprise. I can easily import "typescript-collections" (as instructed on this page) if I had set my module option to commonjs in my tsconfig.json. However, as soon as I change it to "umd" or "amd", I get error (see the screenshot…
3
votes
0 answers

Webpacking UMD modules

I am webpack newbie, so I apologize in advance if I am trying to use Webpack for something it isn't made for. I am publishing my first library with webpack. I have tons of UMD modules in my project and in node (or commonjs) environment I want to…
Mishra
  • 85
  • 3
  • 9
3
votes
0 answers

Webpack umd seemingly breaks stacktrace-js functionality

We're trying to use stacktrace-js with the awesome logary-js (my project) but after going through webpack it would seem it doesn't work anymore. Here's the configuration for webpack…
Henrik
  • 9,714
  • 5
  • 53
  • 87
2
votes
0 answers

How to enable building UMD bundle again with Angular 13

We have a JavaScript library and for building we use an Angular library project workspace. This JavaScript library is not consumed by an Angular application. Actually we need the output to be in UMD format. When I upgraded Angular to 13, I found…
Dávid Paksy
  • 61
  • 1
  • 6
2
votes
1 answer

Webpack: How to export a single class as a UMD library?

In my project semantic-version, I am exporting a UMD bundle with webpack. When imported with in a HTML file, the interesting single class is then available under SemVersion.SemVersion() (
Bill
  • 143
  • 1
  • 10
2
votes
0 answers

Webpack 5 React component library UMD bundle with SourceMaps

I am attempting to make a webpack 5 build process to create a react component library I just had a couple of things cannot seem to get working. #1) The webpack build command works fine, and when using the inline-source-map option I can SEE the data…
wontonman2
  • 25
  • 1
  • 7
2
votes
1 answer

Webpack 5 cannot import UMD module

I recently upgraded to Webpack 5 and I'm having some trouble importing UMD modules. In particular, I'm trying to import Leaflet. Leaflet seems to export a UMD module created by rollup.js, which looks like this: (function (global, factory) { typeof…
cdauth
  • 6,171
  • 3
  • 41
  • 49
2
votes
0 answers

How can I fix the "Error: 'default' is not exported by..." when using formdata-node default import?

Summary I feel like I've hit my head against a wall too many times trying to figure out where I may be going wrong. I have a simple piece of typescript code: import FormDataI from 'formdata-node' const c = new FormDataI() export { c } That im…
Justin Dalrymple
  • 630
  • 9
  • 15
2
votes
0 answers

Using UMD modules in the browser environment

I am building a website and am using es6 modules in development which I need to transpile into a more browser compatible format. One option seems to be UMD - Universal Module Definition, which states it runs in the browser and other environments. I…
Jonny
  • 1,053
  • 1
  • 13
  • 26
2
votes
3 answers

How can I get full string of my JavaScript UMD package in window environment? `.toString()` is not working

I have a UMD bundle of my package called utils, it only has one method called sum like this: Now, I want to get the full string of my UMD…
Joseph
  • 3,974
  • 7
  • 34
  • 67
2
votes
0 answers

if dependencies were already baked in in dist.js by webpack, why does npm still download the dependencies in the package.json when installing

I'm building a umd library using webpack, in my package.json I have dependency-a which I use in my code. When I build my code using webpack, I see that dependency-a is already baked in in the dist/bundle.js, then I publish my code to npm. When the…
Kevin
  • 2,775
  • 4
  • 16
  • 27