Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

web-worker doesn't work with typescript and nextjs #2753

@iSuslov

Description

@iSuslov

Overview

web-worker doesn't work with typescript and nextjs. Suggested babel-loader only works with js files.
Nextjs uses webpack5 and bunch of own loaders.
Adding

module: {
    rules: [
      {
        test: /\.js/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
            options: {
              babelrc: false,
              plugins: [require.resolve('@shopify/web-worker/babel')],
            },
          },
        ],
      },
    ],
  },

is not enough.

I was able to make it work by modifying webpack config in next.config like this:

import {WebWorkerPlugin} from '@shopify/web-worker/webpack';
/** @type {import('next').NextConfig} */
const nextConfig = {
	webpack: (config, { isServer, nextRuntime, dev }) => {
		config.module.rules.map((r) => {
			if (
				r.issuerLayer === "app-pages-browser" &&
				Array.isArray(r.use) &&
				Array.isArray(r.resolve.mainFields)
			) {
				r.use.push({
					loader: "babel-loader",
					options: {
						babelrc: false,
						plugins: [import.meta.resolve("@shopify/web-worker/babel")],
					},
				});
			}
			return r;
		});
		config.plugins.push(
			new WebWorkerPlugin({
				globalObject: "self",
			}),
		);

		return config;
	},
};
export default nextConfig;

So the appropriate rule looks like this:
Screenshot 2024-04-09 at 3 40 45 AM

But this solution feels flakey.

Consuming repo

https://github.com/Shopify/quilt/tree/main/packages/web-worker

Scope

  • Is this issue related to a specific package?

    • @shopify/web-worker
    • @shopify/react-web-worker

Checklist

  • Please delete the labels section before submitting your issue
  • I have described this issue in a way that is actionable (if possible)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions