Skip to content

Commit

Permalink
@uppy/companion: fix esm imports in production/transpiled builds
Browse files Browse the repository at this point in the history
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.
This unfortunately breaks in `@types/vfile` which is a transitive dependency of `stylelint-config-rational-order` which has a dependency on an outdated `stylelint` version:

```
yarn why -R @types/vfile
└─ @uppy-dev/build@workspace:.
   └─ stylelint-config-rational-order@npm:0.1.2 (via npm:^0.1.2)
      └─ stylelint@npm:9.10.1 (via npm:^9.10.1)
         └─ postcss-markdown@npm:0.36.0 [23902] (via npm:^0.36.0 [23902])
            └─ remark@npm:10.0.1 (via npm:^10.0.1)
               └─ unified@npm:7.1.0 (via npm:^7.0.0)
                  └─ @types/vfile@npm:3.0.2 (via npm:^3.0.0)
```

Newer versions of `stylelint` do not have this dependency anymore, which is why I set the resolution in `package.json`.
  • Loading branch information
dschmidt committed Jul 8, 2023
1 parent ded685e commit 0562283
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 872 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
"@types/webpack-dev-server": "^4",
"preact": "patch:preact@npm:10.10.0#.yarn/patches/preact-npm-10.10.0-dd04de05e8.patch",
"pre-commit": "patch:pre-commit@npm:1.2.2#.yarn/patches/pre-commit-npm-1.2.2-f30af83877.patch",
"start-server-and-test": "patch:start-server-and-test@npm:1.14.0#.yarn/patches/start-server-and-test-npm-1.14.0-841aa34fdf.patch"
"start-server-and-test": "patch:start-server-and-test@npm:1.14.0#.yarn/patches/start-server-and-test-npm-1.14.0-841aa34fdf.patch",
"webdav@^5.2.2": "patch:webdav@npm%3A5.2.2#./.yarn/patches/webdav-npm-5.2.2-791e72c3de.patch",
"stylelint": "^14"
}
}
1 change: 1 addition & 0 deletions packages/@uppy/companion/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"outDir": "./lib",
"module": "commonjs",
"moduleResolution": "node16",
"declaration": true,
"target": "es6",
"noImplicitAny": false,
Expand Down
Loading

0 comments on commit 0562283

Please sign in to comment.