Default exports for Uppy's JS modules
See original GitHub issueHi, 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.
- If so, I’ll wait for the exports to be changed and will then contribute the rest of the typings.
- 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:
- Created 5 years ago
- Comments:9 (4 by maintainers)
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
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 withCommonJS module.exports
onUppy.js:2183
- which isLine 2183: module.exports = Uppy;
Any suggestions? Is there any webpacker settings that you recommend.