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
9
votes
2 answers

Using umd globals with modules in a Typescript project

I am trying to get the Leaflet library to play well with my Typescript project. My project follows the commonJs pattern (imports\exports in my source files), but when I build with webpack, the compiler gives me the following errors from my files…
mindparse
  • 6,115
  • 27
  • 90
  • 191
9
votes
3 answers

Webpack umd library return Object.default

I'm writing a lib with webpack with these settings: output: { path: path.join('build'), filename: 'my_lib.js', library: 'MyLib', libraryTarget: 'umd' }, MyLib: export default function() { console.log('MyLib'); } The problem is,…
gtournie
  • 4,143
  • 1
  • 21
  • 22
7
votes
1 answer

How to fix handlebars 'module not found' in typescript when compiling to umd

I am trying to use handlebars in a client side javascript library that I am writing in typescript, when I use the import * as Handlebars from 'handlebars' I get an error message saying that typescript "cannot find module typescript" I have tried…
Mark Davies
  • 1,447
  • 1
  • 15
  • 30
7
votes
1 answer

Compiling typescript with UMD option into a single file

I'm working on a typescript project that uses import/export style syntax for modules. I want to compile all the typescript files into a single file. Here is how my tsconfig.json looks like, { "compilerOptions": { "module": "UMD", …
VJAI
  • 32,167
  • 23
  • 102
  • 164
7
votes
2 answers

Webpack UMD: Critical dependency... cannot be statically extracted

I'm trying to build a umd library with webpack; regardless of what I do get a warning: WARNING in D:/Code/Node/sample.io/source/index.ts 3:24 Critical dependency: require function is used in a way in which dependencies cannot be statically…
Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
6
votes
0 answers

Typescript: How to declare a default export also being a UMD namespace?

In typescript there's this syntax to declare a 'bundle' of all of a module's exports as a UMD global namespace. From the docs: export function isPrime(x: number): boolean; export as namespace mathLib; This declares a UMD global mathLib that serves…
JJWesterkamp
  • 7,559
  • 1
  • 22
  • 28
6
votes
1 answer

Importing UMD built module using webpack leads to Critical Dependency errors

I am trying to build a simple file that depends on a library built with UMD exports. // main.ts import { parseTree } from 'jsonc-parser'; const tree = parseTree('{ "name: "test" }'); console.log(tree); It compiles fine, however webpack spits out…
jtheoof
  • 585
  • 6
  • 10
6
votes
1 answer

Angular2, systemjs, Failed to use Rx.umd.js

With the recent version of Angular RC4, Rxjs is available with node_modules or npmcdn.com directory. Successful plunker but not using .umd.js http://plnkr.co/edit/B33LOW?f=systemjs.config.js&p=preview This is the Network tab screenshot of…
allenhwkim
  • 27,270
  • 18
  • 89
  • 122
6
votes
1 answer

Avoid bundling lib dependencies with webpack + handlebars loader

I'm writing a library using handlebars templates and I want to use Webpack to bundle it. I'm using handlebars-loader so that I can require and precompile the templates. However I don't want handlebars (nor handlebars/runtime) to be included in my…
Quentin Roy
  • 7,677
  • 2
  • 32
  • 50
5
votes
1 answer

Webpack using perf_hooks for node/browser module

I'm making a module that I would like to be available in the browser and Node. It relies on performance, which is giving me trouble with Webpack and the perf_hooks module in Node. No matter what I do I can only get it where it works in one or the…
Joe Jankowiak
  • 1,059
  • 12
  • 37
5
votes
2 answers

Using ES Modules with babel-standalone

Quoting babel docs https://babeljs.io/docs/en/babel-standalone#usage : "If you want to use your browser's native support for ES Modules, you'd normally need to set a type="module" attribute on your script tag. With @babel/standalone, set a…
George Kamar
  • 134
  • 1
  • 12
5
votes
1 answer

Babel 7 modules UMD - why transpeiler defines global item in lower case and how to avoid it?

This using Babel 7 (configured for modules UMD) import '@babel/polyfill'; import Popper from 'popper.js'; was transpiled to (function (global, factory) { if (typeof define === "function" && define.amd) { //... } else { var mod = { …
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
5
votes
1 answer

Combine multiple es6 classes into single library using rollup js

How can I import a.js and b.js and export as combined bundle.js in UMD format using rollupjs? Here is the example: //a.js export default class A { ... } //b.js export default class B { ... } My current rollup.config.js is: export default [ { …
sungl
  • 1,155
  • 1
  • 7
  • 16
5
votes
1 answer

How to import with ECMAScript (vanilla javascript) with modules es6

I read this post and i want use D3.js (v4+) using only import statement like this: import { selection } from '../node modules/d3/build/d3.js'; But, because code output is UMD (or read this) and can't import because some globals is no defined, and…
5
votes
1 answer

What environment is expected by `if(typeof exports === 'object')` in UMD definition

Webpack generates the following UMD definition: (function webpackUniversalModuleDefinition(root, factory) { // this is CommonJS/Node if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); //…
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
1
2
3
13 14