question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't create UMD build which can be required by Node

See original GitHub issue

Do you want to request a feature or report a bug?

bug

What is the current behavior?

If you require a module in the target output UMD you get this error:

ReferenceError: window is not defined
    at Object.<anonymous> (/mnt/c/Users/foo/webpack-umd-node/dist/main.js:1:272)

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

You shouldn’t see a ReferenceError.

If this is a feature request, what is motivation or use case for changing the behavior?

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Node v8.9.4, webpack v4.0.0-beta.2


According to https://webpack.js.org/configuration/output/#module-definition-systems the UMD build should not include window.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:64
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

31reactions
bhovhannescommented, Mar 7, 2018

Setting globalObject: 'typeof self !== \'undefined\' ? self : this' produces exactly the same UMD header as in WebPack 3

10reactions
donaldpipowitchcommented, Feb 19, 2018

With target: 'node' it throws Uncaught ReferenceError: global is not defined if the UMD build is loaded in the browser 😄

globalObject: 'this' works for Node and the browser. Is this a new setting? I haven’t seen it before. Is this the right way to do it or is it a bug that I need to do that? I’ll update my linked example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack UMD: Critical dependency... cannot be statically ...
when I try to require('./index.js') the generated index.js I get: Error: Cannot find module "." For completeness here are all my files ...
Read more >
Bundling with Rollup: Build CommonJS to UMD
How to build a Rollup bundle to UMD, CJS, and IIFE formats for CommonJS modules. ... in node_modules , you need to install...
Read more >
NPM Support - Babylon.js Documentation
We first run npm init to generate package.json . You can generate package.json in any other way you wish. After package,json was generated,...
Read more >
How to write and build JS libraries in 2018 - Medium
We can't leave var EventBus = require('eventbus') like it was in source. UMD looks nice, but simple nano-libraries is not a case for...
Read more >
You may not need a bundler for your NPM library
I'd recommend just compiling your code with tsc , no bundler involved. This way, you can develop with typescript, it will output js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found