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.

Webpack build is broken

See original GitHub issue

We are now seeing d is not a function in our babel/webpack-built app.

image

The error happens in loggers.js, but that could be triggered by an issue with the spread operator.

_Originally posted by @jlowcs in https://github.com/transloadit/uppy/issues/3328#issuecomment-990141390_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
jlowcscommented, Dec 10, 2021

Alright, we actually decided to turn loose off on our app, and it did the trick. Thanks for your help @aduh95!

1reaction
jlowcscommented, Dec 9, 2021

Context

For more context, in the case of our app, we are transpiling (loose: true) uppy’s code with babel, since uppy contains ES2015+ code. We are also minimizing it.

Diagnostic

Source of the exception

Investigating using the dev tools, I can confirm that the issue is indeed coming from the following line from the bundle:

const steps = [..._classPrivateFieldLooseBase(this, _preProcessors)[_preProcessors], ..._classPrivateFieldLooseBase(this, _uploaders)[_uploaders], ..._classPrivateFieldLooseBase(this, _postProcessors)[_postProcessors]];

The minimized transpiled code for that line looks like this:

s = [].concat(l(this, k)[k], l(this, R)[R], l(this, I)[I])

Later, the code does:

d = s[u]
// ...
d(c.fileIDs, t);

But, l(this, k)[k] is apparently a Set, therefore d is a Set, and therefore not a function.

Ouch, that code is hard to read

For better readability, I tried compiling without minification:

steps = [].concat(_classPrivateFieldLooseBase(this, _preProcessors)[_preProcessors], _classPrivateFieldLooseBase(this, _uploaders)[_uploaders], _classPrivateFieldLooseBase(this, _postProcessors)[_postProcessors])
// ...
fn = steps[step];
// ...
return fn(updatedUpload.fileIDs, uploadID);

Basically, babel replaces the spread operators with the use of [].concat(), which makes sense. But concat doesn’t spread iterables (which Set is).

Explanation of the issue

That all comes from the fact that [].concat(new Set(), new Set(), new Set()) returns an array of Set, not an array of values from those Set.

image

That’s why the Array.from() solution was suggested, as this seems to work much better:

image

What about the legacy bundle?

I actually thing the issue is also present in the legacy bundle, since it is also using Set and the same [].concat() approach:

image

image

Possible solutions

  1. go back to using Array.from (and figure out why it was not working for netdown)
  2. replace the 3 Set with simple arrays
  3. ?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack suddenly broke - Stack Overflow
Webpack suddenly broke ... Any idea what could broke and why? How to fix it? ... It is a same error I get...
Read more >
[BUG] Webpack 5 Broken Bundle · Issue #12014 - GitHub
I would build bundle by command npm run build . After that I get complete bundle. But when I change some value I...
Read more >
“It works on my machine”. When Webpack is broken ... - Medium
The initial step of creating a Webpack build process took a while. One of the reasons is that RPM package builders must run...
Read more >
After upgrading to v5.12.1 from v5.11, webpack build breaks
11, webpack build breaks. Howdy! I started getting an error in my CI/CD pipeline last night after upgrading my project to v5.
Read more >
How I solved and debugged my Webpack issue through trial ...
This is a massive issue, since we cannot just rewrite it every time something is not working! Create-react-app in the best source to...
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