-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@uppy/companion: fix esm imports in production/transpiled builds #4561
Conversation
0562283
to
63ed867
Compare
Good to know, however there's already a dependabot PR to address that, could you remove those changes from this PR? |
Styelint upgrade have landed, could you please rebase and remove the unrelated changes please? |
TypeScript is used to transpile companion to CommonJS. `require()` in CommonJS is synchronous and cannot be used to import packages using ESM syntax, which are asynchronous by spec. If you want to import an ESM package, you need to use asynchronous dynamic `import()`. By default TypeScript transpiles this to `Promise.resolve().then(() => require('webdav'))` which is obviously using synchronous `require` internally and breaks the import of ESM packages. We need to switch `moduleResolution` to `node16` to make TypeScript not transpile the `import()` call.
63ed867
to
93972dc
Compare
done - thanks for that fix in the other PR, that's way nicer than my approach :) (wish I had started the effort 3 days later, haha) |
| Package | Version | Package | Version | | ---------------------- | ------- | ---------------------- | ------- | | @uppy/aws-s3-multipart | 3.5.0 | @uppy/locales | 3.2.3 | | @uppy/box | 2.1.2 | @uppy/onedrive | 3.1.2 | | @uppy/companion | 4.7.0 | @uppy/provider-views | 3.4.0 | | @uppy/companion-client | 3.2.1 | @uppy/react | 3.1.3 | | @uppy/core | 3.3.1 | @uppy/status-bar | 3.2.2 | | @uppy/dashboard | 3.4.2 | @uppy/transloadit | 3.2.0 | | @uppy/dropbox | 3.1.2 | @uppy/utils | 5.4.1 | | @uppy/google-drive | 3.2.0 | uppy | 3.12.0 | - @uppy/transloadit: fix error message (Antoine du Hamel / #4572) - @uppy/provider-views: add support for remote file paths (Mikael Finstad / #4537) - @uppy/transloadit: implement Server-sent event API (Antoine du Hamel / #4098) - @uppy/aws-s3-multipart: add support for signing on the client (Antoine du Hamel / #4519) - @uppy/react: allow `id` from props (Merlijn Vos / #4570) - @uppy/aws-s3-multipart: fix lint warning (Antoine du Hamel / #4569) - @uppy/status-bar: listen to `upload` event instead of button click (Antoine du Hamel / #4563) - @uppy/aws-s3-multipart: fix support for non-multipart PUT upload (Antoine du Hamel / #4568) - @uppy/companion: fix esm imports in production/transpiled builds (Dominik Schmidt / #4561) - @uppy/locales: fix expression and spelling errors in es_ES (Rubén / #4567) - meta: upgrade dev dependencies (dependabot\[bot\]) - meta: Don't use triage label (Artur Paikin / #4552) - meta: update Cypress (Antoine du Hamel / #4562) - @uppy/box,@uppy/companion,@uppy/dropbox,@uppy/google-drive,@uppy/onedrive,@uppy/provider-views: Load Google Drive / OneDrive lists 5-10x faster & always load all files (Merlijn Vos / #4513) - @uppy/locales: Add missing pt-BR locales for ImageEditor plugin (Mateus Cruz / #4558)
see #4551 for context.
This change is needed for me to be able to sanely import the
webdav
library in a provider.While not strictly necessary at this point and it can also be worked around (with
eval("import('webdav')")
), it seems like a good idea to be prepared for other esm libraries at some point.Especially after I spent some time debugging this, I feel like you could benefit from this because it enables you to use esm dependencies.
Moreover, this prevents introducing new dependencies that will block esm dependencies at a later point.
TypeScript is used to transpile companion to CommonJS.
require()
in CommonJS is synchronous and cannot be used to import packages using ESM syntax, which are asynchronous by spec. If you want to import an ESM package, you need to use asynchronous dynamicimport()
. By default TypeScript transpiles this toPromise.resolve().then(() => require('webdav'))
which is obviously using synchronousrequire
internally and breaks the import of ESM packages. We need to switchmoduleResolution
tonode16
to make TypeScript not transpile theimport()
call.See https://www.typescriptlang.org/docs/handbook/esm-node.html for more information on
moduleResolution