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.

@shopify/web-worker does not support chunkFilename being a function #2807

@swissspidy

Description

@swissspidy

Overview

In webpack, output.chunkFilename can be either a string or a function returning a string.

However, the webpack loader in @shopify/web-worker assumes it is only a string:

chunkFilename: addWorkerSubExtension(
compiler.options.output.chunkFilename as string,
),

function addWorkerSubExtension(file: string) {
return file.includes('[name]')
? file.replace(/\.([a-z]+)$/i, '.worker.$1')
: file.replace(/\.([a-z]+)$/i, '.[name].worker.$1');
}

This leads to TypeError: file.includes is not a function errors when using something like

output: {
	chunkFilename: (pathData) => {
			console.log(pathData.chunk.name);
			return '[name].js';
		},
}

To fix this, first check whether it's a function, and then maybe add a wrapper function that adds the suffix.

Consuming repo

What repo were you working in when this issue occurred?

https://github.com/swissspidy/media-experiments

Area

  • Add any relevant Area: <area> labels to this issue

Scope

  • Is this issue related to a specific package?

    • Tag it with the Package: <package_name> label.

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions