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
5
votes
0 answers

How to write and distribute a Javascript module for both NPM and direct browser use

I want to write a single Javascript module that can be used both through NPM/Browserify: let mymodule=require('mymodule'); mymodule.foo() and alternatively by linking to a hosted version without building:
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
5
votes
2 answers

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

I tried this the last two days and I can't get it to work like expected: I want to build my own JavaScript library and register it under an already existing namespace ("OCA" - in this particular case). And as you might understand, I don't want to be…
janis91
  • 83
  • 1
  • 8
5
votes
2 answers

How does browserify bundle a universal module

I know browserify can consume UMD modules by means of transforms, but when I want to build a lib using browserify, how can I build an UMD module? Is there any transform I can use?
hjl
  • 2,794
  • 3
  • 18
  • 26
5
votes
2 answers

Is it reasonable to use UMD with no exports, to simply augment a dependency?

I'm creating my first AngularJS module intended for open source distribution. I'd like to package it in a way that's easy for others to consume. The UMD project provides a pattern for exporting JavaScript modules that are compatible with AMD,…
Bungle
  • 19,392
  • 24
  • 79
  • 106
4
votes
1 answer

How can I expose a global variable with Vite library mode?

I'm trying to use Vite to build a script file that can load a global variable into a web page. I'm using library mode: https://vitejs.dev/guide/build.html#library-mode. This is my entry file. I'm trying to expose a global with init/destroy methods…
Oliver Tuck
  • 41
  • 1
  • 2
4
votes
0 answers

Transforming UMD modules to ES modules in RollupJS ("The requested module X does not provide an export named 'default'")

I am currently having a TypeScript project that includes Ethers.js, which in turn includes bn.js. The problem is SyntaxError: The requested module './../../../bn.js/lib/bn.js' does not provide an export named 'default' It appears to me this is…
Veksi
  • 3,556
  • 3
  • 30
  • 69
4
votes
1 answer

How do I import UMD in ESM?

I have a UMD library and the following works in commonjs... global.window = global; var DoSomething = require("../dist/sce-umd.js").DoSomething; (function(){ var instance = new DoSomething(); instance.doSomethingElse(); })() I am trying to…
Jackie
  • 21,969
  • 32
  • 147
  • 289
4
votes
0 answers

Webpack using [name] for output.library with multiple entry points

I'm trying to output two libraries from my entry points but I seem to be unable to use [name] for output.library much like output.filename. I've also tried putting it into an array per webpack docs…
bradley
  • 445
  • 1
  • 9
  • 17
4
votes
1 answer

How to convert my CommonJS module to UMD?

I'm new to UMD and AMD. I've written a JS library in Browserify and I've just came across UMD. My understanding is if I include a piece of code for every module, my module should be able to be used in CommonJs and AMD. Here's my sample…
toy
  • 11,711
  • 24
  • 93
  • 176
4
votes
1 answer

Consuming a UMD created by Webpack results in duplicate libs in output

Library I'm creating a React.js library and trying to package it as a UMD for distribution. In the library, the webpack.config.js file is as follows: module.exports = { entry: [ __dirname+'/modules/index.js' ], output: { path:…
Ben Sargent
  • 41
  • 1
  • 3
4
votes
2 answers

Javascript UMD - where/how are root, factory defined?

In a simple UMD setup like the following, where/how are root and factory defined? (function (root, factory) { // environment detection here console.log(root); console.log(factory); }(this, function (b) { // module definition…
David R.
  • 684
  • 6
  • 12
3
votes
0 answers

Including a specific module in rollup build

I'm using Rollup to build a UMD version of my module. This rollup.config.js successfully builds my module, without including @tensorflow/tfjs: import path from 'path'; import commonjs from '@rollup/plugin-commonjs'; import { nodeResolve } from…
thekevinscott
  • 5,263
  • 10
  • 44
  • 57
3
votes
0 answers

Import umd bundle in Angular

I'm trying to import an umd.js file into an angular project. The module (library) is declared as follows: (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'),…
Zeno Trevisan
  • 517
  • 1
  • 8
  • 23
3
votes
2 answers

React component bundled as an UMD can't load a dependency when imported via script tag in another react app

I created a simple react component and I want to import it conditionally to another react app. I've managed to import it via HTML script tag and then get it from the window variable. The whole idea was working as long as react was being bundled in…
czerwiukk
  • 31
  • 1
  • 3
3
votes
0 answers

How come i can use es6 import for libraries which produce commonJS and UMD bundles only?

I was wondering I am used to work with Webpack and bundle my own libraries to UMD and ESM. But now I see that some of the libraries I am using, do not even create ESM bundles. Even though, I am able to import them using es6 syntax!. If it is the…
Moshe Kerbel
  • 121
  • 7
1 2
3
13 14