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.

Devtool breaks UMD exports with webpack-dev-server

See original GitHub issue

Bug report

What is the current behavior?

After loading my bundle window.quickstarts = {}.

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

webpack.config.js:

module.exports = {
  mode: 'development',
  devtool: 'inline-cheap-source-map',
  entry: {
    quickstarts: {
      import: __dirname + '/entry.js',
      filename: 'quickstarts.js',
      library: {
        name: 'quickstarts',
        type: 'umd'
      }
    }
  }
}

entry.js:

export function myExport() { console.log('some data'); }

The output at http://localhost:8080/quickstarts.js erroneously contains:

var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
var __webpack_exports__ = {}; // THIS SHOULDN'T BE HERE?!
/*!******************!*\
  !*** ./entry.js ***!
  \******************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "myExport": () => (/* binding */ myExport)
/* harmony export */ });
function myExport() { console.log('some data'); }

})();

Minimal Github repo: https://github.com/redallen/webpack-umd-bug

What is the expected behavior?

I expect __webpack_exports__ to not be defined in the IIFE scope so that it contains myExport and then window.quickstarts will contain it as well.

Other relevant information: webpack version:

    "webpack": "^5.28.0",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"

Node.js version: v14.16.0 Operating System: linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
redallencommented, Mar 25, 2021

The beta release fixes it.

The release cycle surrounding webpack@5 and webpack-cli/webpack-dev-server has been rather confusing – I hope to see some version incompatibility notices in the future!

0reactions
alexander-akaitcommented, Mar 31, 2021

@ianks sorry, this message is not helpful, please provide example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dev server breaks library entry type #4469 - GitHub
UMD is not exported while devServer inline is on. webpack#12793 (Also says fixed in wds 4). I don't really care about having hot...
Read more >
DevServer - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
How to troubleshoot missing external libraries from Webpack ...
I am trying to create a reusable d3 library, building the code with Babel 7 and then bundling a JS file with Webpack...
Read more >
Output
The top-level output key contains set of options instructing webpack on how and where it should output your bundles, assets and anything else...
Read more >
配置 | webpack
This file should export the configuration object: ... "umd" - Export to AMD, CommonJS2 or as property in root. Default: "var". If output.library...
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