Skip to content
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

[Typescript] NOT adding polyfill to the web worker scope #33

Open
gaplo917 opened this issue Dec 14, 2020 · 0 comments
Open

[Typescript] NOT adding polyfill to the web worker scope #33

gaplo917 opened this issue Dec 14, 2020 · 0 comments

Comments

@gaplo917
Copy link

gaplo917 commented Dec 14, 2020

Reproduce:

  1. Create React App
npx create-react-app my-app  --template typescript
cd my-app
npm start
  1. Use react-app-rewired to customize Webpack

  2. In config-overrides.js, add the comlink-loader at the top of rules

/**
 * Config to override webpack config from create-react-app
 */
const { override } = require('customize-cra');
module.exports = override((config, env) => {
  config.module.rules.unshift({
    test: /\.worker.singleton\.(js|ts)$/i,
    loader: 'comlink-loader',
    options: {
      singleton: true
    }
  });
  config.module.rules.unshift({
    test: /\.worker\.(js|ts)$/i,
    loader: 'comlink-loader',
    options: {
      singleton: false
    }
  });
  return config;
});

  1. create a task.worker.singleton.ts
export async function test(): string {
  return "something".replaceAll('s', 'g')
}

Actual: In an old version browser (i.e. Android simulator), It will throw .replaceAll() is not a function

Expected: comlink-loader will bundle the polyfill to all .worker.ts to sync with the non-worker js file.

Solution

Add the Polyfill manaully.

import 'core-js';
import 'regenerator-runtime/runtime';

export async function test(): string {
  return "something".replaceAll('s', 'g')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant