diff --git a/.depcheckrc.yml b/.depcheckrc.yml index db1103c0e303..7ce26732fcf7 100644 --- a/.depcheckrc.yml +++ b/.depcheckrc.yml @@ -74,6 +74,7 @@ ignores: - 'https-browserify' # polyfill - 'path-browserify' # polyfill - 'nyc' # coverage + - 'core-js-pure' # polyfills # babel - '@babel/plugin-transform-logical-assignment-operators' # trezor diff --git a/development/webpack/webpack.config.ts b/development/webpack/webpack.config.ts index 3cef5fc3fc53..d207b3ae741c 100644 --- a/development/webpack/webpack.config.ts +++ b/development/webpack/webpack.config.ts @@ -142,6 +142,14 @@ const plugins: WebpackPluginInstance[] = [ Buffer: ['buffer', 'Buffer'], // Make a global `process` variable that points to the `process` package. process: 'process/browser', + // polyfill usages of `setImmediate`, ideally this would be automatically + // handled by `swcLoader`'s `env.usage = 'entry'` option, but that setting + // results in a compilation error: `Module parse failed: 'import' and + // 'export' may appear only with 'sourceType: module' (2:0)`. I spent a few + // hours trying to figure it out but couldn't. So, this is the workaround. + // Note: we should probably remove usages of `setImmediate` from our + // codebase so we don't have to polyfill it. + setImmediate: 'core-js-pure/actual/set-immediate', }), new CopyPlugin({ patterns: [ diff --git a/package.json b/package.json index af20530a7bda..59c6735a5d64 100644 --- a/package.json +++ b/package.json @@ -557,6 +557,7 @@ "concurrently": "^8.2.2", "contentful": "^10.8.7", "copy-webpack-plugin": "^12.0.2", + "core-js-pure": "^3.38.0", "cross-spawn": "^7.0.3", "crypto-browserify": "^3.12.0", "css-loader": "^6.10.0", @@ -754,7 +755,8 @@ "@pmmmwh/react-refresh-webpack-plugin>core-js-pure": true, "@swc/core": true, "@lydell/node-pty": true, - "$root$": true + "$root$": true, + "core-js-pure": true } }, "packageManager": "yarn@4.2.2" diff --git a/yarn.lock b/yarn.lock index e78af63a50ad..de5963fd90b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15584,10 +15584,10 @@ __metadata: languageName: node linkType: hard -"core-js-pure@npm:^3.0.0, core-js-pure@npm:^3.23.3": - version: 3.30.2 - resolution: "core-js-pure@npm:3.30.2" - checksum: 10/52bba8bf4bfdec61c3459244a4f349393dd9890307df698993f0c575abc891c5dda9ff8d2af7fc8d4abdef06e6babe48483ddc44749760557b3015406b8d2acc +"core-js-pure@npm:^3.0.0, core-js-pure@npm:^3.23.3, core-js-pure@npm:^3.38.0": + version: 3.38.0 + resolution: "core-js-pure@npm:3.38.0" + checksum: 10/56a0346bb691f0a9eddd88e92daa29213f3591c4db84731fe47c89dfb7bab116c9c1bd983a2286a558a35b736312da2d0ccb603a40d73af6857bd22b352f2988 languageName: node linkType: hard @@ -26163,6 +26163,7 @@ __metadata: contentful: "npm:^10.8.7" copy-to-clipboard: "npm:^3.3.3" copy-webpack-plugin: "npm:^12.0.2" + core-js-pure: "npm:^3.38.0" cross-spawn: "npm:^7.0.3" crypto-browserify: "npm:^3.12.0" css-loader: "npm:^6.10.0"