Browse Source

@uppy/companion: fix esm imports in production/transpiled builds (#4561)

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.
Dominik Schmidt 1 year ago
parent
commit
7dcf8c2f36
1 changed files with 1 additions and 0 deletions
  1. 1 0
      packages/@uppy/companion/tsconfig.json

+ 1 - 0
packages/@uppy/companion/tsconfig.json

@@ -2,6 +2,7 @@
   "compilerOptions": {
     "outDir": "./lib",
     "module": "commonjs",
+    "moduleResolution": "node16",
     "declaration": true,
     "target": "es6",
     "noImplicitAny": false,