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.

Default exports for Uppy's JS modules

See original GitHub issue

Hi, all,

I’m using Uppy inside a React/Typescript environment, and I noticed the typings file for the Uppy React components was empty. So…

With #1131, I opened a PR that adds Typescript typings for the Uppy React components. I succeeded for the React components themselves, but… While doing this, I noticed that I had to write some painful code when importing the plugins, e.g. aws-s3-multipart and webcam. So, I stopped after writing the typings for these two plug-ins. The others will need to be changed as well!

I could not simply write

import AwsS3Multipart from '@uppy/aws-s3-multipart';
import Webcam from '@uppy/webcam';

but I had to write

import AwsS3Multipart = require('@uppy/aws-s3-multipart');
import Webcam = require('@uppy/webcam');

The reason is that the JS files in Uppy have this piece of code at the end:

module.exports = someThing;

instead of

export default someThing;

When I use import...from, the Typescript code is transpiled to use module.exports.default which is undefined and causes the Typescript code to crash. When I use import...=require(...), Typescript uses module.exports for the import and succeeds.

Is there a reason why you use module.exports instead of export default?

Before I continue to contribute more typings to Uppy, I’d like to know whether you want to move towards true default exports in the near future.

  1. If so, I’ll wait for the exports to be changed and will then contribute the rest of the typings.
  2. If not, I’ll write all the typings like I did now with the consequence of a painful import syntax for the Typescript users of this project.

What would you folks prefer?

Cheers, Matthias

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Meistercoach83commented, May 17, 2021

Hey there! I´m trying to use Uppy in an Angular Application - and I get errors like this: " … depends on ‘@uppy/core’. CommonJS or AMD dependencies can cause optimization bailouts. For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies"

So is there a plan of disabling commonJS?

@arturi

3reactions
antonysastrecommented, Jan 31, 2022

Is this issue resolved somewhere else? Saw @arturi’s comment you’re looking for a best way around the issue. Did you find a way?

I’m using Uppy with rails/webpacker and I’m getting: Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>' which is, as i understand it, an issue with CommonJS module.exports on Uppy.js:2183 - which is Line 2183: module.exports = Uppy;

Any suggestions? Is there any webpacker settings that you recommend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Named Exports over Default Exports in JavaScript
Default Exports vs Named Exports. The export statement is used when creating JavaScript modules and you want to share objects, functions, ...
Read more >
export - JavaScript - MDN Web Docs
Every module can have two different types of export, named export and default export. You can have multiple named exports per module but...
Read more >
Default Exports in JavaScript Modules Are Terrible
In this article, I want to explain why default exports are a poor practice and lead to a worse developer experience. Consider an...
Read more >
Why does JavaScript have default exports? - Stack Overflow
Some want modules in the conventional sense, as encapsulated namespaces with named exports, which you can import and access qualified or ...
Read more >
How to define a default export with vanilla JS ES modules
Yesterday, we learned how to use import and export with ES modules. Today, we're going to learn about another export pattern: default ......
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