Skip to content

Commit dd21d68

Browse files
committed
try to get rid of top-level await
1 parent 2f975d7 commit dd21d68

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.0.1
2+
3+
- try to get rid of top-level await
4+
15
### 3.0.0
26

37
- fix for Deno 2 and removal of unnecessary .cjs file

lib/request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ if (typeof fetchApi !== 'function') fetchApi = undefined
3131

3232
if (!fetchApi && !XmlHttpRequestApi && !ActiveXObjectApi) {
3333
try {
34-
fetchApi = (await import('cross-fetch')).default
34+
// top-level await is not available on everywhere
35+
// fetchApi = (await import('cross-fetch')).default
36+
import('cross-fetch').then((mod) => {
37+
fetchApi = mod.default
38+
}).catch(() => {})
3539
} catch (e) {}
3640
}
3741

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"license": "MIT",
7474
"config": {
75-
"fixcjs": "fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace(`(await Promise.resolve().then(function () {\n return _interopRequireWildcard(require('cross-fetch'));\n })).default`, `require('cross-fetch')`))"
75+
"fixcjs": "fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace(`Promise.resolve().then(function () {\n return _interopRequireWildcard(require('cross-fetch'));\n }).then(function (mod) {\n fetchApi = mod.default;\n }).catch(function () {});`, `fetchApi = require('cross-fetch');`))"
7676
},
7777
"scripts": {
7878
"lint": "eslint .",

0 commit comments

Comments
 (0)