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

Add preLoadModules option to import modules on main thread #1777

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

astron8t-voyagerx
Copy link

@astron8t-voyagerx astron8t-voyagerx commented Apr 23, 2024

Description

This commit adds 'preLoadModules' option that allows the main thread to load specified modules.

Motivation and Context

Some Node.js modules, such as 'sharp', are not safe to use with worker threads. Importing them in a worker thread can lead to crashes. There are several reported issues regarding this, for example, see:
#1603

And 'sharp' recommends importing the module on the main thread to prevent such problems.
lovell/sharp#2263 (comment)

While the 'useInProcess' option allows us to avoid using threading, it also disables hot reloading, which significantly reduces convenience. This commit implements the 'preLoadModules' option (e.g., preLoadModules: "sharp, canvas") to import these modules before creating worker threads.

How Has This Been Tested?

I've tested in my own project using serverless offline, and also conducted tests with Mocha in this repository.

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

Successfully merging this pull request may close these issues.

None yet

1 participant